I asked a question previously (see: Sequence of Timestamps with Milliseconds) however for some reason when my time starts as 00:00:00 my code does not work.
I would like to get a sequence of 10hz times from one time to another. However this code is giving me:
1 2018-06-01 00:00:00.000
2 2018-06-01 00:00:00.101
3 2018-06-01 00:00:00.202
4 2018-06-01 00:00:00.303
5 2018-06-01 00:00:00.404
When I need:
1 2018-06-01 00:00:00.000
2 2018-06-01 00:00:00.100
3 2018-06-01 00:00:00.200
4 2018-06-01 00:00:00.300
5 2018-06-01 00:00:00.400
Code:
options(digits.secs=3)
Time1 ="2018-06-01 00:00:00"
Time2 ="2018-06-01 00:00:10"
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')
library(stringr)
dif_T2_T1 <- difftime(Time1, Time2, units = 'secs')
pattern <- '(\\d)+'
n <- as.numeric(str_extract(dif_T2_T1, pattern = pattern)) * 10
df_blank <- data.frame(Timestamp = as.character(seq.POSIXt(Time1, Time2, units = 'seconds', length.out = n)))