r - as.POSIXct/as.POSIXlt doesn't like .61 milliseconds -
here's weird artifact. i'm converting tens of thousands of character vectors datetime class, so:
alles$datetime=as.posixct(alles$roughdate, tz="est",format="%y%m%d.%h%m%s.%os")
pretty straight forward. character string (alles$roughdate
) in format yyyymmdd.hhmmss.ss
.ss
being milliseconds. above code works, expected. however, if milliseconds equal .61, returns na instead of date time value.
this isn't bad, when dealing tens of thousands cells, few hundred returned na. milliseconds .61, doesn't matter rest of date is. need dates.
i've tried isolating files , merging 2 data frames again, doesn't seem work. of dates na.
any thoughts?
example
vec <- c("20150101.010101.60", "20150101.010101.61", "20150101.010101.62") as.posixlt(vec, tz="est", format="%y%m%d.%h%m%s.%os") #[1] "2015-01-01 01:01:60 est" na "2015-01-01 01:01:01 est"
if change format time part %h%m%os
instead of %h%m%s.%os
, seems parse correctly. may have adjust options
see this:
as.posixlt(vec, tz = "est", format = "%y%m%d.%h%m%os") #[1] "2015-01-01 01:01:01 est" "2015-01-01 01:01:01 est" #[3] "2015-01-01 01:01:01 est" options(digits.secs = 2) as.posixlt(vec, tz = "est", format = "%y%m%d.%h%m%os") # [1] "2015-01-01 01:01:01.60 est" "2015-01-01 01:01:01.61 est" # [3] "2015-01-01 01:01:01.62 est"
Comments
Post a Comment