Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中的lubridate包中使用'difftime'函数查找日期向量中的连续差异?_R - Fatal编程技术网

在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)