I have a large unbalanced data set where I would like to add 12 additional months to each unique group of identifiers
Here is an example of data:
| X | Y | Z | year_month |
|---|---|---|---|
| aaa | bbb | ccc | 2008-09-01 |
| aaa | bbb | ccc | 2008-10-01 |
| aaa | ddd | eee | 2010-06-01 |
| aaa | ddd | eee | 2010-07-01 |
| aaa | ddd | eee | 2010-08-01 |
Here is what I would like the data set to look like:
| X | Y | Z | year_month |
|---|---|---|---|
| aaa | bbb | ccc | 2007-09-01 |
| ... | ... | ... | ... |
| aaa | bbb | ccc | 2008-08-01 |
| aaa | bbb | ccc | 2008-09-01 |
| aaa | bbb | ccc | 2008-10-01 |
| aaa | ddd | eee | 2009-06-01 |
| ... | ... | ... | ... |
| aaa | ddd | eee | 2010-05-01 |
| aaa | ddd | eee | 2010-06-01 |
| aaa | ddd | eee | 2010-07-01 |
| aaa | ddd | eee | 2010-08-01 |
I've tried isolating the earliest date for each unique identifier and then adding the date 12 months prior. I then use padr but the results end up adding every day. At least that is what I believe it is doing since this runs for hours. Here is my code:
test <- date_filler %>%
group_by(X, Y, Z) %>%
do(pad(date_filler, interval = "month"))
Any help would be appreciated thank you!