Hi I have 2 dates in r and I want to have a sequence from one date to the other by months but for some reason is missing the last date, any way to correct this?
this is my code
max(data1$Sign.up.Date)
[1] "2022-07-01"
min(data1$Sign.up.Date)
[1] "2020-02-27"
dates <- seq(min(data1$Sign.up.Date), max(data1$Sign.up.Date) ,by = "month")
> dates
[1] "2020-02-27" "2020-03-27" "2020-04-27" "2020-05-27" "2020-06-27" "2020-07-27" "2020-08-27" "2020-09-27" "2020-10-27"
[10] "2020-11-27" "2020-12-27" "2021-01-27" "2021-02-27" "2021-03-27" "2021-04-27" "2021-05-27" "2021-06-27" "2021-07-27"
[19] "2021-08-27" "2021-09-27" "2021-10-27" "2021-11-27" "2021-12-27" "2022-01-27" "2022-02-27" "2022-03-27" "2022-04-27"
[28] "2022-05-27" "2022-06-27"
I am missing 2022-07-01 as another period, maybe is because 2022-07 only goes to the first day? any way to get that 2022-07 in there?
CodePudding user response:
Does this give you what you're after?
date_range <- lubridate::floor_date(range(data1$Sign.up.Date), "month")
seq(date_range[1], date_range[2], by = "month")