gpt4 book ai didi

r - 使用 lubridate 计算每分钟速率

转载 作者:行者123 更新时间:2023-12-04 04:37:19 27 4
gpt4 key购买 nike

我正在尝试使用包 lubridate 在 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

如何计算每分钟的费率?我特别想要使用 lubridate 包的解决方案

最佳答案

首先将您的period 转换为分钟:

count/(period_to_seconds(time)/60)
# [1] 2.271293 4.237918 0.200000 1.200000 3.000000

关于r - 使用 lubridate 计算每分钟速率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19527774/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com