When generating a list of times and dates in R as.posixct %OS3 is outputting "NA" but %S works

45 Views Asked by At

I am trying to generate a list of dates and times at 0.0625 second intervals from a given date and time using lubridate and at.posixct. When I use a whole second value I have no issues, but when I try and use %OS3 to get decimal seconds it outputs NA NA NA.

z <- seq(1, length.out=nrow(ctd1), by=1)
calendarTime <- as.POSIXct("2023-11-04 01:40:46.111", 
                           format="%Y-%m-%d %H:%M:%S", tz='UTC') +  
lubridate::period(0.0625,'second') * z  
print(calendarTime)

[1] "2023-11-04 01:40:46 UTC" "2023-11-04 01:40:46 UTC" "2023-11-04 01:40:46 UTC" "2023-11-04 01:40:46 UTC"
[5] "2023-11-04 01:40:46 UTC" "2023-11-04 01:40:46 UTC" "2023-11-04 01:40:46 UTC" "2023-11-04 01:40:46 UTC"
[9] "2023-11-04 01:40:46 UTC" "2023-11-04 01:40:46 UTC" "2023-11-04 01:40:46 UTC" "2023-11-04 01:40:46 UTC"

calendarTime <- as.POSIXct("2023-11-04 01:40:46.111", 
                           format="%Y-%m-%d %H:%M:%OS3", tz='UTC') + 
lubridate::period(0.0625,'second') * z  
print(calendarTime)

[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[39] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[77] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

I tried various iterations of this including changing the date format as well as updating XQuartz and R and reinstalling tidyverse but I'm still having the same issue.

0

There are 0 best solutions below