使用chron包或修改精度以百分之一秒的速度工作



我正在使用chron包,并且我试图在百分之一秒内工作,像这样:

library(chron)
tms <- times(c("00:01:30.81", "00:01:33.38", "00:01:34.10", "00:01:37.09", 
               "00:01:37.29", "00:01:36.96", "00:01:37.65", "00:01:37.63", 
               "00:01:36.80", "00:01:40.06"))
mean(tms)
# [1] 00:01:36
var(tms)
# [1] 9.432812e-10
sum(tms)
# [1] 00:16:02

时间不是以百分之一秒计算的,就像我这样做的:

tms
# [1] 00:01:31 00:01:33 00:01:34 00:01:37 00:01:37 00:01:37 00:01:38 00:01:38
# [9] 00:01:37 00:01:40

它只使用秒,就是这样,它是四舍五入的,我想要确切的时间,或者平均值…我怎样才能解决这个问题呢?

它在那里,但它只显示秒部分。试试这个:

# x should be a times object
show100s <- function(x) sprintf("%s.%02d", format(x), 
    round(100 * 3600 * 24 * (as.numeric(x) - as.numeric(trunc(x, "sec")))))

,然后像这样运行:

library(chron)
tt <- times("11:12:13.81")
tt
## [1] 11:12:14
show100s(tt)
## [1] "11:12:14.81"

最新更新