使用chron包处理或修改精度,使用一秒钟的hundreths

nat*_*rro 5 r

我正在使用chron包,我正在尝试使用一秒钟的hundreths,如下所示:

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
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

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

G. *_*eck 6

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

# 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")))))
Run Code Online (Sandbox Code Playgroud)

并像这样运行:

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