posixct

Converting character to timestamp in dataframe

旧街凉风 提交于 2019-12-01 22:46:53
I have a timestamp in a dataframe that is recognized as a character class. For some reason, I am not able to convert it to a poxis timestamp. Here is a sample of the data. ID dateTime stage 1 2016-11-01T00:00:00.000Z 4.82 2 2016-11-01T00:15:00.000Z 4.83 3 2016-11-01T00:30:00.000Z 4.84 4 2016-11-01T00:45:00.000Z 4.85 5 2016-11-01T01:00:00.000Z 4.86 6 2016-11-01T01:15:00.000Z 4.87 I have tried using the following. format(df$dateTime, "Y%-%m-%d %h:%m") as.Date(df$dateTime, "Y%-%m-%d %h:%m") as.POSIXct(df$dateTime, tz="GMT") None of the attempts above worked. After trying each, the class would

Trouble with date format using the function as.POSIXct in R

荒凉一梦 提交于 2019-12-01 20:57:22
I'm working with a date format of YYYY-mm-ddTHH:MM:SS.000Z (2014-02-05T08:45:01.326Z) or that has a separator T that separates the date from the time, and time indicator Z or "Zulu time" (UTC). I'm trying to store the timestamp as a class POSIXct using the following function: timestamp <- as.POSIXct(strptime(as.character(data$Time), tz = "UTC", "%Y-%m-%d %H:%M:%S")) at the moment I'm getting NA's. If anyone has some advice on how I can incorporate the 'T' and 'Z' indicators in my conversion I will highly appreciate it. You can include the characters in your format string: d <- "2014-02-05T08

Extracting 2 digit hour from POSIXct in R

泄露秘密 提交于 2019-12-01 10:34:05
I would like to extract the hour from a POSIXct time in R, but retrieve the 2 digit answer. For example, test=as.POSIXct("2015-03-02 03:15:00") test [1] "2015-01-02 03:15:00 GMT" month(testing) [1] 1 hour(testing) [1] 3 The results give the relevant month and hour, but I would like to see 01 and 03 instead of just 1 and 3 . Try to do this: strftime(test, format="%H") to extract hours and strftime(test, format="%m") for month 来源: https://stackoverflow.com/questions/35227648/extracting-2-digit-hour-from-posixct-in-r

Decompose xts hourly time series

。_饼干妹妹 提交于 2019-12-01 07:32:40
I want to decompose hourly time series with decompose , ets , or stl or whatever function. Here is an example code and its output: require(xts) require(forecast) time_index1 <- seq(from = as.POSIXct("2012-05-15 07:00"), to = as.POSIXct("2012-05-17 18:00"), by="hour") head(time_index1 <- format(time_index1, format="%Y-%m-%d %H:%M:%S", tz="UTC", usetz=TRUE) # [1] "2012-05-15 05:00:00 UTC" "2012-05-15 06:00:00 UTC" # [3] "2012-05-15 07:00:00 UTC" "2012-05-15 08:00:00 UTC" # [5] "2012-05-15 09:00:00 UTC" "2012-05-15 10:00:00 UTC" head(time_index <- as.POSIXct(time_index1)) # [1] "2012-05-15 05:00

Converting to Local Time in R - Vector of Timezones

一笑奈何 提交于 2019-12-01 06:48:50
I have a set of data from across the US that I am trying to convert into local time for each "subject". I have UTC timestamps on each event and have converted those into POSIXct format, but every time I try to include a vector of tz = DS$Factor or tz = as.character(DS$Factor) in any of the POSIXct/POSIXlt functions (including format() and strftime() ) I get an error that says: Error in as.POSIXlt.POSIXct(x, tz = tz) : invalid 'tz' value If I just enter tz = 'US/Eastern' it works fine, but of course not all of my values are from that time zone. How do I get the time stamps into local time for

Decompose xts hourly time series

本秂侑毒 提交于 2019-12-01 05:02:42
问题 I want to decompose hourly time series with decompose , ets , or stl or whatever function. Here is an example code and its output: require(xts) require(forecast) time_index1 <- seq(from = as.POSIXct("2012-05-15 07:00"), to = as.POSIXct("2012-05-17 18:00"), by="hour") head(time_index1 <- format(time_index1, format="%Y-%m-%d %H:%M:%S", tz="UTC", usetz=TRUE) # [1] "2012-05-15 05:00:00 UTC" "2012-05-15 06:00:00 UTC" # [3] "2012-05-15 07:00:00 UTC" "2012-05-15 08:00:00 UTC" # [5] "2012-05-15 09:00

R extract time components from semi-standard strings

前提是你 提交于 2019-12-01 04:07:06
Setup I have a column of durations stored as a strings in a dataframe. I want to convert them to an appropriate time object, probably POSIXlt . Most of the strings are easy to parse using this method : > data <- data.frame(time.string = c( + "1 d 2 h 3 m 4 s", + "10 d 20 h 30 m 40 s", + "--")) > data$time.span <- strptime(data$time.string, "%j d %H h %M m %S s") > data$time.span [1] "2012-01-01 02:03:04" "2012-01-10 20:30:40" NA Missing durations are coded "--" and need to be converted to NA - this already happens but should be preserved. The challenge is that the string drops zero-valued

How to initialize data.frame with column of type POSIXct?

血红的双手。 提交于 2019-12-01 03:02:23
I can initialize a data.frame via df <- data.frame(a=numeric(), b=character()) But how do I define a column of type POSIXct? df <- data.frame(a=numeric(), b=character(), c=POSIXct()) won't work. konvas You can try df <- data.frame(a=numeric(), b=character(), c=as.POSIXct(character())) Similarly, you can create a POSIXct column of NA s in a data frame with > 0 rows by creating a new column with as.POSIXct(NA) . An additional tip to the above initialization: If you begin rbind() activities to add rows to this empty data frame, you may encounter an error like the following if you follow this

Subsetting based on co-occurrence within a time window

谁说我不能喝 提交于 2019-12-01 01:43:40
I am having trouble subsetting data based on different attributes in different columns. Here is a dummy data set with species, area where it was found, and time (already in POSIXct). SP Time Area B 07:22 1 F 09:22 4 A 09:22 1 C 08:17 3 D 09:20 1 E 06:55 4 D 09:03 1 E 09:12 2 F 09:45 1 B 09:15 1 I need to subset the rows that have SP==A, plus all other species occurring in the same area (in this case 1), within a time window of +30 and -30 minutes returning this: SP Time Area A 09:22 1 D 09:20 1 D 09:03 1 F 09:45 1 B 09:15 1 I can't get past the conditional statement of this 1-hour window,

R extract time components from semi-standard strings

人盡茶涼 提交于 2019-12-01 01:36:52
问题 Setup I have a column of durations stored as a strings in a dataframe. I want to convert them to an appropriate time object, probably POSIXlt. Most of the strings are easy to parse using this method: > data <- data.frame(time.string = c( + "1 d 2 h 3 m 4 s", + "10 d 20 h 30 m 40 s", + "--")) > data$time.span <- strptime(data$time.string, "%j d %H h %M m %S s") > data$time.span [1] "2012-01-01 02:03:04" "2012-01-10 20:30:40" NA Missing durations are coded "--" and need to be converted to NA -