I have longitudinal data with >100 rows per subject representing daily observations. I want to collapse columns, by subject ID, into monthly observations (i.e. have multiple rows per ID that are summarizing every 30 rows (days) of data).
How can you specify such groupings of days using dplyr?
Also of note, all subjects have different total number of days
Edit: data sample below
df<-structure(list(ID = structure(c(100087, 100087, 100087, 100087,
100087, 100087, 100087, 100087, 100087, 100087, 100087, 100087,
100087, 100087, 100087, 100087, 100087, 100087, 100087, 100087)), time = structure(c(0, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)),
BMI = structure(c(20.06, 20.06, 20.06, 20.06, 20.06, 20.06,
20.06, 20.06, 20.06, 20.06, 20.06, 20.06, 20.06, 20.06, 20.06,
20.06, 20.06, 20.06, 20.06, 20.06)), Dis = structure(c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
Drug1 = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1)), Drug2 = structure(c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))