I would like to generate a sequence of all months between two dates.
I can achieve this with seq.Date :
start <- as.Date("2015-08-01")
end <- as.Date("2015-09-01")
seq <- seq.Date(start, end, by = "month")
[1] "2015-08-01" "2015-09-01"
format(seq, "%Y-%m")
[1] "2015-08" "2015-09"
But it fails if there is less than a month ellapsed between the two dates :
start <- as.Date("2015-08-14")
end <- as.Date("2015-09-03")
seq <- seq.Date(start, end, by = "month")
[1] "2015-08-14"
format(seq, "%Y-%m")
[1] "2015-08"
I can work around with seq by days :
unique(format(seq.Date(start, end, by = "day"), "%Y-%m"))
[1] "2015-08" "2015-09"
But is there a more straightforward way to do this that I'm missing ? Thanks.