I have a dataset like the example one below. I want to create a variable (i.e., Submission_date.last) which takes the last value of another variable (i.e., Submission_date) based on the sequence of another variable (i.e., repeat) whereby 0 indicates the start of a new sequence.
I have got the below code, but don't know where to go from here. Any help is appreciated, thanks!
df %>%
group_by(ID) %>%
arrange(Submission_date) %>%
mutate(Submission_date.last = Submission_date[]) # I'm not sure what to put on this line to correctly create the variable?
ID Submission_date Repeat Submission_date.last
1 25/07/19 0 31/07/19
1 30/07/19 1 31/07/19
1 31/07/19 2 31/07/19
1 11/08/20 0 14/08/20
1 14/08/20 1 14/08/20
2 30/07/19 0 30/07/19
2 31/08/20 0 31/08/20
3 13/09/20 0 15/09/20
3 15/09/20 1 15/09/20
3 18/07/21 0 22/07/21
3 21/07/21 1 22/07/21
3 22/07/21 2 22/07/21