我试着用润滑油包计算R中每分钟的速率。以下是我所要尝试的:
library(lubridate)
time <- ms(c("5M 17S", "4M 29S", "5M 0S", "5M 0S", "5M 20S"))
count <- sample(1:20, 5)
count/time这会引发错误:
Error in count/time : Cannot divide numeric by period我如何计算每分钟的费率?我特别想要的是使用润滑油包的解决方案
发布于 2013-10-22 20:44:24
首先将period转换为分钟:
count/(period_to_seconds(time)/60)
# [1] 2.271293 4.237918 0.200000 1.200000 3.000000发布于 2013-10-22 21:28:27
它不太漂亮,但是:
time <- c("5m 17s", "4m 29s", "5m0s", "5m0s", "5m20s")
count <- sample(1:20, 5)
countTime <- function(count, time){
require(lubridate)
time <- ms(time)
timeConvert <- period_to_seconds(time)/60
countTime <- count/timeConvert
return(countTime)
}
countTime(count, time)
[1] 3.028391 1.338290 1.800000 3.600000 2.437500https://stackoverflow.com/questions/19527774
复制相似问题