, , - , . . R difftime .
tms <- c("2:06:00", "3:34:30", "4:12:59", "08:09:10",
"09:10:11", "10:11:12", "11:12:13")
ta <- as.difftime(tms)
> ta
Time differences in hours
[1] 2.100000 3.575000 4.216389 8.152778 9.169722 10.186667 11.203611
attr(,"tzone")
[1] ""
> format(ta)
[1] " 2.100000 hours" " 3.575000 hours" " 4.216389 hours" " 8.152778 hours" " 9.169722 hours"
[6] "10.186667 hours" "11.203611 hours"
.
> 42.2/as.numeric(ta)
[1] 20.095238 11.804196 10.008564 5.176150 4.602102 4.142670 3.766643
lubridate , , duration.
library("lubridate")
ti <- as.duration(as.difftime(tms))
> ti
[1] 7560s (~2.1 hours) 12870s (~3.58 hours) 15179s (~4.22 hours) 29350s (~8.15 hours)
[5] 33011s (~9.17 hours) 36672s (~10.19 hours) 40333s (~11.2 hours)
and you can do the math with after converting to numeric (here, seconds, not hours)
> 42.2/as.numeric(ti)
[1] 0.005582011 0.003278943 0.002780157 0.001437819 0.001278362 0.001150742 0.001046290
source
share