I'm using the chron package and I'm trying to work with hundreths of a second, like this:
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
That the times are not being taken with the hundredths of a second, as when I do this:
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
it's only using seconds and that's it, it's rounding, I want the exact times, or average... how could I fix this?
Its there but its only displaying the seconds part. Try this:
# 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")))))
and run it like this:
library(chron)
tt <- times("11:12:13.81")
tt
## [1] 11:12:14
show100s(tt)
## [1] "11:12:14.81"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With