1

Following on from: How R formats POSIXct with fractional seconds, I have two distinct (character) timestamps that are converted to the same POSIXct value using fastPOSIXct from the fasttime package:

library(fasttime)
tmpstmp <- c("2010-03-01 12:41:52.713",
             "2010-02-01 12:41:52.714")
options(digits.secs = 6) # note that this is required to display fractional seconds in R.    
fastPOSIXct(tmpstmp)

giving

> fastPOSIXct(tmpstmp)
[1] "2010-03-01 23:41:52.713 AEDT" "2010-02-01 23:41:52.713 AEDT"

which is very undesirable behaviour. My workaround is to concatenate 10 microseconds, so that I now have

tmpstmp <- c("2010-03-01 12:41:52.71301",
             "2010-02-01 12:41:52.71401")

giving

> fastPOSIXct(tmpstmp)
[1] "2010-03-01 23:41:52.71301 AEDT" "2010-02-01 23:41:52.71401 AEDT"

I would now like to round this POSIXct object down to the nearest millisecond. How do I do this?

Community
  • 1
  • 1
Alex
  • 15,186
  • 15
  • 73
  • 127
  • 2
    `fastPOSIXct(tmpstmp)` on my machine doesn't even show the milliseconds: `"2010-03-01 12:41:52 GMT" "2010-02-01 12:41:52 GMT"` - have you set something somwhere? fasttime: Version: 1.0-1 – Spacedman Oct 24 '16 at 09:02
  • 1
    A common pitfall with R timestamps! Does `options(digits.secs = 6)` work for you? – Alex Oct 24 '16 at 09:23
  • It's the same in base R: `options(digits.secs = 3); as.POSIXct("2010-02-01 12:41:52.714", format = "%Y-%m-%d %H:%M:%OS", tz = "GMT")`, which probably means it's a floating point issue in the underlying OS libraries. – Roland Oct 24 '16 at 10:16
  • The precision at the millisecond level should be a floating point issue indeed. – Alex Oct 24 '16 at 10:19
  • Did you find an answer to this? – h.l.m Nov 26 '19 at 13:43

0 Answers0