I have a large dataframe containing IDs and a start date of intervention for each ID:
ID Date
1 1 17228
2 2 17226
3 3 17230
And I would like to add 2 rows to each ID with subsequent dates as the values in those rows:
ID Date
1 1 17228
2 1 17229
3 1 17230
4 2 17226
5 2 17227
6 2 17228
7 3 17230
8 3 17231
9 3 17232
Is there any way using dplyr if possible? Other ways are also fine!
df1[rep(seq_len(nrow(df1)), each = 3),]
or using tidyversedf1 %>% uncount(3)
– akrundf1 %>% uncount(3) %>% group_by(ID) %>% mutate(Date = seq(Date[1], length.out = n(), by = 1))
– akrun