Hi,
I have a grouped dataframe (grouped by Date, ID and Type). This DF has also a column, Period, that is consist of some days (between 0 and 360). I want to group first 30 days in 5 days range such as 0-5, 5-10, 10-15 etc. and I want to sum Value column grouping Date, ID and Type columns. I want to group all other days after 30 days as 30-90, 90-120, 120-360. After this manipulation I will spread this column with tidyr library.
My DF:
Date | ID | Type | Period | Value |
---|---|---|---|---|
2021-08-07 | 123 | A | 1 | 10 |
2021-08-07 | 123 | A | 3 | 12 |
2021-08-07 | 123 | A | 9 | 20 |
2021-08-07 | 222 | A | 15 | 3 |
2021-08-08 | 123 | A | 1 | 10 |
2021-08-08 | 123 | A | 3 | 5 |
2021-08-08 | 123 | A | 9 | 17 |
2021-08-08 | 222 | A | 15 | 8 |
It will be like:
Date | ID | Type | Period | Value |
---|---|---|---|---|
2021-08-07 | 123 | A | 0-5 | 22 |
2021-08-07 | 123 | A | 6-10 | 20 |
2021-08-07 | 222 | A | 11-15 | 3 |
2021-08-08 | 123 | A | 0-5 | 15 |
2021-08-08 | 123 | A | 6-10 | 17 |
2021-08-08 | 222 | A | 11-15 | 8 |
Thank you!