Q:

Why is R seq.Date is skipping months

When I want to list all the months between two dates, seq.Date seems to skip dates.  I am definitely making a mistake in my code somewhere, but it is so simple, can't seem to get it right.
Help would be appreciated.
seq.Date(as.Date("2017-01-31"),as.Date("2017-06-30"),by = "months")

Regards,
Aksel

A:

If you really need the last day of the month, one possibility would be to construct a sequence of the first day of the following months and then subtract 1 day.  For example:
> seq.Date(as.Date("2017-02-01"),as.Date("2017-07-01"),by = "months") - 1
[1] "2017-01-31" "2017-02-28" "2017-03-31" "2017-04-30" "2017-05-31" "2017-06-30"

A:

Its because your dates are the last day of the month, and I believe seq.Date will add the number of days from the month that it started in. 
If we look at diff of the output from your example:
seq.Date(as.Date("2017-01-31"),as.Date("2017-06-30"),by = "months")
[1] "2017-01-31" "2017-03-03" "2017-03-31" "2017-05-01" "2017-05-31"

diff(seq.Date(as.Date("2017-01-31"),as.Date("2017-06-30"),by = "months"))
Time differences in days
[1] 31 28 31 30

So it looks like seq.Date is adding 31 days because it starts in January, and then adds February's 28 days etc.
Probably better to use different dates, and maybe combining with some lubridate floor_date or ceiling_date

