How do I get a sequence of monthly dates that ends on a given month and has a given length? seq(as.Date(*), length, by="month")
assumes the start date is given, not the end date, and AFAIK it's impossible to specify a negative value for by
in this case.
ETA: that is, I want a sequence that spans a given period, but one whose end point is specified rather than the start point. So, something like seq(to="2000-03-01", len=3, by="month") --> 2000-01-01, 2000-02-01, 2000-03-01
.
Try this:
rev(seq(as.Date("2000-03-01"), length = 3, by = "-1 month"))
## [1] "2000-01-01" "2000-02-01" "2000-03-01"
library(lubridate)
ymd('2011-03-03') - months(0:5)
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