在R中,如何计算2次之间还剩多少时间?
例如: 如果我有在R中,如何计算2次之间还剩多少时间?,r,R,例如: 如果我有 x <- "2016-11-23 16:22:03 IST" y <- "2016-11-23 16:28:29 IST" x试试这个: x <- strptime("2016-11-23 16:22:03 IST", format = '%Y-%m-%d %H:%M:%S') y <- strptime("2016-11-23 16:28:29 IST", format = '%Y-%m-%d %H:%M:%S') y-x #Time diffe
x <- "2016-11-23 16:22:03 IST"
y <- "2016-11-23 16:28:29 IST"
x试试这个:
x <- strptime("2016-11-23 16:22:03 IST", format = '%Y-%m-%d %H:%M:%S')
y <- strptime("2016-11-23 16:28:29 IST", format = '%Y-%m-%d %H:%M:%S')
y-x
#Time difference of 6.433333 mins
x首先,将字符转换为datetime对象,然后计算两者之间的差异。可以是diff(lubridate::ymd_hms(c(x,y))
。但是还有其他选择。as.POSIXct(x)-as.POSIXct(y)
或difftime(as.POSIXct(x),as.POSIXct(y))
?请避免回答重复的问题。我知道你在被标记为欺骗之前已经回答了。简单地搜索“r日期时间差”会得到许多关于这个主题的已有帖子。