在R中的lubridate包中使用'difftime'函数查找日期向量中的连续差异?
我目前有一个名为在R中的lubridate包中使用'difftime'函数查找日期向量中的连续差异?,r,R,我目前有一个名为dates的日期向量,它是使用ymd_hms函数获取的 dates <- c("2013-09-01 23:05:24", "2013-09-02 22:51:09", "2013-09-04 00:09:16", "2013-09-04 23:43:31", "2013-09-06 00:17:41", "2013-09-06 22:42:27", "2013-09-08 00:22:27") ymd_hms(dates) 但是我需要时间里的日期、秒等规格 谢谢 您可
dates
的日期向量,它是使用ymd_hms函数获取的
dates <- c("2013-09-01 23:05:24", "2013-09-02 22:51:09", "2013-09-04 00:09:16", "2013-09-04 23:43:31", "2013-09-06 00:17:41", "2013-09-06 22:42:27", "2013-09-08 00:22:27")
ymd_hms(dates)
但是我需要时间里的日期、秒等规格
谢谢 您可能没有意识到
ymd\u hms(日期)
不会更改“日期”。diff
不需要任何函数。(不确定difftime
是什么。)diff
是。。。。矢量化
dates <- c("2013-09-01 23:05:24", "2013-09-02 22:51:09", "2013-09-04 00:09:16", "2013-09-04 23:43:31", "2013-09-06 00:17:41", "2013-09-06 22:42:27", "2013-09-08 00:22:27")
realdates <-ymd_hms(dates)
diff(realdates)
日期
dates <- c("2013-09-01 23:05:24", "2013-09-02 22:51:09", "2013-09-04 00:09:16", "2013-09-04 23:43:31", "2013-09-06 00:17:41", "2013-09-06 22:42:27", "2013-09-08 00:22:27")
realdates <-ymd_hms(dates)
diff(realdates)