I want to create a time series from a start date&time (t1) to a finish date&time (t2) by 10 minute intervals.

the code below works fine for all other t2 times bar 23:50:00

library(chron)
t1 <- chron("1/1/2006", "00:00:00")
t2 <- chron("1/3/2006", "23:50:00")
deltat <- times("00:10:00")
tt <- seq(t1, t2, by = times("00:10:00"))

I have tried this code in Rstudio on both linux and windows platforms, as well as from terminal on linux, to no avail.

any thoughts would be appreciated.

有帮助吗?

解决方案

You have a floating point issue. To get around it, you could add an additional second to t2

t2 = chron("1/3/2006", "23:50:01")
seq(t1, t2, by = times("00:10:00"))

Search for floating point on stack overflow. In R, the classic example is

R> sqrt(2)^2 ==2
[1] FALSE
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top