I am struggling to make a sequence of timestamps in a dataframe from one time to another with milliseconds. I can do this easily with seconds but I am running into problems when using milliseconds.
options(digits.secs=1)
Time1 = "2018-06-26 14:12:00.0"
Time2 = "2018-06-28 14:34:00.0"
Time1 <- as.POSIXct(Time1 , format = "%Y-%m-%d %H:%M:%OS",tz = "UTC")
Time2 <- as.POSIXct(Time2 , format = "%Y-%m-%d %H:%M:%OS",tz = "UTC")
df <- data.frame(DateTime = as.character(seq.POSIXt(Time1,Time2,units = "milliseconds", by = 1)))
This returns just a sequence of seconds:
1 2018-06-26 14:12:00
2 2018-06-26 14:12:01
3 2018-06-26 14:12:02
4 2018-06-26 14:12:03
5 2018-06-26 14:12:04
I also tried an altered version of this post Create a series of timestamps along milliseconds in R:
df <- data.frame(DateTime = as.character(seq.POSIXt(Time1, Time2, units = "seconds", by = .1)))
This returns a strange sequence:
1 2018-06-26 14:12:00.0
2 2018-06-26 14:12:00.0
3 2018-06-26 14:12:00.2
4 2018-06-26 14:12:00.2
5 2018-06-26 14:12:00.4
6 2018-06-26 14:12:00.5
What I am trying to create:
1 2018-06-26 14:12:00.0
2 2018-06-26 14:12:00.1
3 2018-06-26 14:12:00.2
4 2018-06-26 14:12:00.3
5 2018-06-26 14:12:00.4
6 2018-06-26 14:12:00.5
...
...