[英]how to calculate time interval and divide it by integer in r?
我有时间字符串为“08:00”,“06:00”,我想计算它们之间的差异,并将它除以15分钟。
然后结果应该是8整数,我不知道如何在R中编码
有人可以帮帮我吗?
使用difftime
这样的东西?
difftime(
as.POSIXct("08:00", format = "%H:%M"),
as.POSIXct("06:00", format = "%H:%M"),
units = "mins") / 15
#Time difference of 8 mins
或转换为numeric
as.numeric(
difftime(as.POSIXct("08:00", format = "%H:%M"),
as.POSIXct("06:00", format = "%H:%M"),
units = "mins") / 15)
#[1] 8
使用lubridate
会很容易,我们将hm
格式的字符串转换为15分钟。
library(lubridate)
(hm(a) - hm(b))/minutes(15)
#[1] 8
数据
a <- "08:00"
b <- "06:00"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.