,使用seq,我可以得到一个日期序列
seq(as.Date('2014-02-01'), as.Date('2014-8-31'), by='1 month')
[1] "2014-02-01" "2014-03-01" "2014-04-01" "2014-05-01" "2014-06-01" "2014-07-01" "2014-08-01"
我如何获得一对价值观?序列上的值间隔
"2014-02-01" "2014-03-01"
"2014-03-01" "2014-04-01"
...
答案 0 :(得分:4)
如果你想要一个清单,你可以这样做:
s1 = seq(as.Date('2014-02-01'), as.Date('2014-8-31'), by='1 month')
Map(c, head(s1, -1), tail(s1, -1))
#[[1]]
#[1] "2014-02-01" "2014-03-01"
#[[2]]
#[1] "2014-03-01" "2014-04-01"
#[[3]]
#[1] "2014-04-01" "2014-05-01"
#[[4]]
#[1] "2014-05-01" "2014-06-01"
#[[5]]
#[1] "2014-06-01" "2014-07-01"
#[[6]]
#[1] "2014-07-01" "2014-08-01"
答案 1 :(得分:3)
你可以尝试
s1 <- seq(as.Date('2014-02-01'), as.Date('2014-8-31'), by='1 month')
d1 <- data.frame(v1=s1[-length(s1)], v2=s1[-1])
d1
# v1 v2
#1 2014-02-01 2014-03-01
#2 2014-03-01 2014-04-01
#3 2014-04-01 2014-05-01
#4 2014-05-01 2014-06-01
#5 2014-06-01 2014-07-01
#6 2014-07-01 2014-08-01