从2个向量之间的日期创建时间序列列表 [英] Create a list of time sequences from dates between 2 vectors
本文介绍了从2个向量之间的日期创建时间序列列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是循环圈的新手。我想执行以下操作,但要针对整个向量:
I'm new to loops. I would like to do the following, but for an entire vector:
library(timedate)
timeSequence("2014-05-09 10:48:00", "2014-05-11 19:39:00", by = "min")
这里是一个示例:
Dates <- data.frame(Start = c("2014-05-09 10:48:00",
"2014-05-11 19:39:00",
"2014-10-09 08:52:00",
"2014-10-29 10:48:59",
"2014-11-13 03:08:00"),
End = c("2014-05-11 19:39:00",
"2014-05-12 07:05:00",
"2014-10-29 10:48:59",
"2014-11-13 03:08:00",
"2014-11-13 08:41:59"))
我从开始:
timeSequence(Dates$Start, Dates$End, by = "min)
但是得到错误'from'的长度必须为1
...
But gets the error 'from' must be of length 1
...
所以我尝试了不同的迭代 for
循环,但没有成功:
So I've tried different iterations of for
loops, with no success:
for (a in Dates$Start) {
for (b in Dates$End) {
Date_List <- timeSequence(a, b, by = "min")
}
}
在这里我在seq.int(0,to0-from,by)中得到 Error:错误登录按自变量
。我想要一个清单,其中每个项目在向量中的日期之间都有完整的顺序。
Here I get Error in seq.int(0, to0 - from, by) : wrong sign in 'by' argument
. I'd like to have a list where each item has the full sequence between dates in the vectors. Thank you so much.
推荐答案
您可以使用 mapply
library(timeDate)
mapply(timeSequence, from = Dates$Start, to = Dates$End, by = "min", SIMPLIFY = FALSE)
这篇关于从2个向量之间的日期创建时间序列列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文