library(dplyr)
df <- tibble(id = c("1", "2", "3", "4"),
start_date = c("2021-01-01", "2021-01-15", "2021-02-03", "2021-05-20"),
end_date = c("2021-10-11", "2021-08-17", "2021-12-20", "2021-07-01"))
df
#> # A tibble: 4 × 3
#> id start_date end_date
#> <chr> <chr> <chr>
#> 1 1 2021-01-01 2021-10-11
#> 2 2 2021-01-15 2021-08-17
#> 3 3 2021-02-03 2021-12-20
#> 4 4 2021-05-20 2021-07-01
What I want to get? Subtract end_date - start_date and fill rows with year-month data:
id start_date year_month
1 2021-01 2021-01
1 2021-01 2021-02
............................
1 2021-01 2021-10
2 2021-01 2021-01
............................
2 2021-01 2021-07
2 2021-01 2021-08
3 2021-02 2021-02
3 2021-02 2021-03
............................
3 2021-02 2021-11
3 2021-02 2021-12
4 2021-05 2021-05
4 2021-05 2021-06
4 2021-05 2021-07
How do I add rows to extend my grouped data?