endDt<-as.Date("2012-10-1")
dts<-as.Date(c("2010-1-1", "2010-3-1", "2012-10-1"))
我如何做以下事情:
endDts<-c() #an empty date vector
for each dt in dts
append seq.Date(dt,endDt,by="3 months") to endDts
next dt
我遇到了试图遍历我的日期向量dts
答案 0 :(得分:1)
除了优秀的评论解决方案,您还可以使用mapply
:
mapply(seq.Date,dts, endDt,by="3 months")
[[1]]
[1] "2010-01-01" "2010-04-01" "2010-07-01" "2010-10-01" "2011-01-01" "2011-04-01" "2011-07-01"
[8] "2011-10-01" "2012-01-01" "2012-04-01" "2012-07-01" "2012-10-01"
[[2]]
[1] "2010-03-01" "2010-06-01" "2010-09-01" "2010-12-01" "2011-03-01" "2011-06-01" "2011-09-01"
[8] "2011-12-01" "2012-03-01" "2012-06-01" "2012-09-01"
[[3]]
[1] "2012-10-01"