I have a dataframe structured like the following:
example <- data.frame(id = c(1,1,1,1,1,1,1,2,2,2,2,2),
event = c("email","email","email","draw","email","email","draw","email","email","email","email","draw"),
date = c("2020-03-01","2020-06-01","2020-07-15","2020-07-28","2020-08-07","2020-09-01","2020-09-15","2020-05-22","2020-06-15","2020-07-13","2020-07-15","2020-07-31"))
I am trying to filter out the emails within each id that don't fall into a range of 30 days before a draw event signified in the event column. This is the result I would like to end up with:
desiredResult <- data.frame(id = c(1,1,1,1,2,2,2),
event = c("email","draw","email","draw","email","email","draw"),
date = c("2020-07-15","2020-07-28","2020-09-01","2020-09-15","2020-07-13","2020-07-15","2020-07-31"))
I just need to only include events that take place within 30 days before each draw event. I'm not sure how to achieve this