Reputation: 49
I create a data set with dates starting from 2010-01-01 to 2010-08-1, with 5-minute intervals.
library(chron)
t1 <- chron("2010/01/01","00:00:00",format=c("y/m/d","h:m:s"))
t2 <- chron("2018/01/01","00:00:01",format=c("y/m/d","h:m:s"))
deltat <- times("00:05:00")
date <- seq(t1,t2,by=times("00:05:00"))
I format the date to follow the ISO 8601 standards using the parsedate package to change the timezone to GMT+2.
library(parsedate)
date1 <- format_iso_8601(as.POSIXlt(date,tz="Etc/GMT+2"))
head(date1)
[1] "2009-12-31T22:00:00+00:00" "2009-12-31T22:05:00+00:00" "2009-12-31T22:10:00+00:00"
[4] "2009-12-31T22:15:00+00:00" "2009-12-31T22:20:00+00:00" "2009-12-31T22:25:00+00:00"
However, when I use View():
View(date1)
The intervals change after observation 510918. I can't understand the reason. The same happens if I change the timezone. How can I fix this?
2014-11-09T22:24:59+00:00
2014-11-09T22:30:00+00:00
2014-11-09T22:35:00+00:00
2014-11-09T22:40:00+00:00
2014-11-09T22:45:00+00:00
2014-11-09T22:50:00+00:00
2014-11-09T22:55:00+00:00
2014-11-09T23:00:00+00:00
2014-11-09T23:05:00+00:00
2014-11-09T23:09:59+00:00
2014-11-09T23:15:00+00:00
2014-11-09T23:20:00+00:00
2014-11-09T23:25:00+00:00
2014-11-09T23:30:00+00:00
2014-11-09T23:35:00+00:00
2014-11-09T23:40:00+00:00
2014-11-09T23:45:00+00:00
2014-11-09T23:50:00+00:00
2014-11-09T23:54:59+00:00
2014-11-10T00:00:00+00:00
2014-11-10T00:05:00+00:00
2014-11-10T00:10:00+00:00
2014-11-10T00:15:00+00:00
2014-11-10T00:20:00+00:00
2014-11-10T00:25:00+00:00
2014-11-10T00:30:00+00:00
2014-11-10T00:35:00+00:00
2014-11-10T00:39:59+00:00
Upvotes: 1
Views: 1935
Reputation: 8187
Do you just want a sequence of dates at 5 min intervals, with a time zone? If so you can use seq.PosiXt
as described here
See my example below:
start_date <- as.POSIXct(paste0("2010/01/01", "00:00:00"), format= "%Y/%m/%d %H:%M:%S", tz = "Etc/GMT+2")
end_date <- as.POSIXct(paste0("2018/01/01","00:00:01"), format= "%Y/%m/%d %H:%M:%S", tz = "Etc/GMT+2")
output <- seq.POSIXt(start_date, end_date, by = "5 min")
formatted <- format_iso_8601(output)
Upvotes: 1