I have been trying to find a solution to this and am unsure if it would require multiple steps using dplyr and/or creating some kind of function. Essentially, I want to create an "event" column with variables that link a sequence/repeat dates and ID together and indicate the event order.
before:
event date id
2020-12-25 111
2020-12-26 111
2020-12-27 111
2020-12-30 222
2020-12-30 222
2021-01-30 333
2021-01-31 333
2021-05-25 222
2021-05-26 222
2021-07-08 222
2021-07-09 222
after:
event date id event
2020-12-25 111 1
2020-12-26 111 1
2020-12-27 111 1
2020-12-30 222 1
2020-12-30 222 1
2021-01-30 333 1
2021-01-31 333 1
2021-05-25 222 2
2021-05-26 222 2
2021-07-08 222 3
2021-07-09 222 3
The process to assign event values is essentially if the id is linked to a sequence of dates that are consecutive, then this can be grouped into an event. If the id is linked to multiple consecutive dates/individual dates, then that is a new and separate event associated with that id.
edit: added more data points to provide more info