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