如何计算时间间隔并将其除以r中的整数?
我的时间字符串是“08:00”,“06:00” 我想计算它们之间的差异 再除以15分钟 那么结果应该是8的整数 我不知道如何在R中编码如何计算时间间隔并将其除以r中的整数?,r,time,R,Time,我的时间字符串是“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 或转换为数字
有人能帮我吗 使用
difftime
执行类似操作
difftime(
as.POSIXct("08:00", format = "%H:%M"),
as.POSIXct("06:00", format = "%H:%M"),
units = "mins") / 15
#Time difference of 8 mins
或转换为数字
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"
a