in R, with seq, I can get a date sequence
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"
how I can get a pair of values? a interval of values over the sequence
"2014-02-01" "2014-03-01"
"2014-03-01" "2014-04-01"
...
If you want a list you can do:
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"
You can try
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With