Looking to classify an existing event date, based on if it falls within 2 dates in another column
My Raw data looks like this:
study_id | Event | Event_Date | Event_Result | Pre1 | CheckUp | Post1 | Pre2 | CheckUp2 | Post2 | Pre3 | CheckUp3 | Post3 | Pre4 | CheckUp4 | Post4 | Pre5 | CheckUp5 | Post5 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | event1 | 5/4/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
1 | event1 | 5/15/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
1 | event1 | 6/5/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
1 | event1 | 7/3/2012 | 0.8 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
2 | event2 | 8/14/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
2 | event2 | 9/11/2012 | 1.2 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
2 | event1 | 9/21/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
3 | event1 | 10/9/2012 | 1.1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
3 | event1 | 10/23/2012 | 1.1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
3 | event2 | 10/25/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
4 | event2 | 11/2/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
4 | event1 | 11/13/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 |
Expected Outcome I am hoping to have a column for each interval rule (see what I have tried section below for interval details, but essentially a total of 10 extra columns), and if the event_Date falls within Interval rule, mark it as TRUE, otherwise false. I was able to do this in Excel, but looking for a solution in R.
See example below.
personID | Event_Date | Event_Result | Pre1 | CheckUp | Post1 | Pre2 | CheckUp2 | Post2 | Pre3 | CheckUp3 | Post3 | Pre4 | CheckUp4 | Post4 | Pre5 | CheckUp5 | Post5 | Interval1 | Interval2 | Interval3 | Interval4 | Interval5 | Interval6 | Interval7 | Interval8 | Interval9 | Interval10 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 5/4/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
1 | 5/15/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
1 | 6/5/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
2 | 7/3/2012 | 0.8 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
2 | 8/14/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
3 | 9/11/2012 | 1.2 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
3 | 9/21/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
3 | 10/9/2012 | 1.1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
4 | 10/23/2012 | 1.1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
4 | 10/25/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
4 | 11/2/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
5 | 11/13/2012 | 1 | 7/23/2012 | 10/23/2012 | 1/23/2013 | 11/25/2013 | 2/25/2014 | 5/25/2014 | 8/1/2014 | 11/1/2014 | 2/1/2015 | 7/4/2015 | 10/4/2015 | 1/4/2016 | 7/4/2016 | 10/4/2016 | 1/4/2017 | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
What I have Tried I have tried to create the intervals to look at the Event_Result and see if it falls within a Range based on the Post, Pre and CheckUp dates. The intervals rules I care about are the following 10:
Interval1 = If EventDate >= Pre1 AND EvenDate <= CheckUp
Interval2 = If EventDate > CheckUp AND EvenDate <= Post1
Interval3 = If EventDate >= Pre2 AND EvenDate <= CheckUp2
Interval4 = If EventDate > CheckUp2 AND EvenDate <= Post2
*
*
Interval9 = If EventDate >= Pre5 AND EventDate <= CheckUp5
Interval10 = If EventDate > CheckUp5 AND EventDate <= Post5
I tried using LUBRIDATE with no luck. As I mentioned I was able to do this in Excel, but just looking for an approach in R (open to LUBRIDATE, DPLYR, or other libraries)
INTERVAL_1 <- interval(ymd(data_merged$Pre1), ymd(data_merged$EventDate))