seq.POSIXct function in R is not able to generate a regular sequence in the format "%Y-%m-%d %H:%M:%OS"?

Viewed 32

I want to create a regular sequence from a start date (e.g. "2021-11-19 09:28:57.95 UTC") to an end date (e.g. "2021-11-20 00:24:21.96 UTC") with time steps of 0.01 seconds.

x1 <- as.POSIXct(strptime("2021-11-19 09:28:57.95", "%Y-%m-%d %H:%M:%OS"), tz = "UTC")
x2 <- as.POSIXct(strptime("2021-11-20 00:24:21.96", "%Y-%m-%d %H:%M:%OS"), tz = "UTC")
testseq <- data.frame(y = seq(x1, x2, by = 0.01))

But the generated sequence often has irregularities. Instead of having a difference of exactly 0.01 seconds, the time difference between two points can be 0.00999999, 0.01000001 or 0.01000023 seconds. I can't find the source of these irregularities and I need to have a perfectly regular sequence with time steps of 0.01 seconds. Here is an illustration of the problem.

A part of the irregular sequence generated The difftime show the decimals problems

I just want the find a way to create a perfectly regular sequence with a level of precision of 0.01 second. I would be grateful if you could help me with this.

0 Answers
Related