Hey all!
I come across problems like this quite regularly and it is one that I always have troubles wrapping my head around for the best tidyverse solution.
Take the example data below:
data <- tibble::tribble(
~id, ~date, ~event,
12345678, "2016-10-14 02:09:50 UTC", "Event A Opt Out",
12345678, "2016-10-14 02:09:56 UTC", "Event B Opt Out",
12345678, "2017-11-20 12:20:17 UTC", "Event B Opt In",
12345678, "2017-11-20 12:20:41 UTC", "Event A Opt In",
87654321, "2016-03-12 09:22:19 UTC", "Event B Opt Out",
87654321, "2017-08-17 11:48:42 UTC", "Event A Opt Out",
87654321, "2017-08-17 11:49:02 UTC", "Event A Opt In"
)
What is the best tidyverse solution to determine date ranges of when each ID was opted in/out for each event?
The end goal is to be able to join back to other data (by id) and a date to see if that id was either opted in or out at that time.
Is creating lubridate intervals and filtering by %within% the best solution? Or what are some other recommendations?