如何将POSIXct四舍五入到最接近的毫秒?

时间:2016-10-24 08:53:42

标签: r timestamp

继续:How R formats POSIXct with fractional seconds后,我有两个不同的(字符)时间戳,使用fastPOSIXct包中的fasttime转换为相同的POSIXct值:

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)

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

这是非常不受欢迎的行为。我的解决方法是连接10微秒,所以我现在有

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

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

我现在想把这个POSIXct对象舍入到最接近的毫秒。我该怎么做?

0 个答案:

没有答案