I'm trying to do a rather complicated filter using if else and I keep getting turned around in circles.
Here is a sample of the data:
individual_id born mom_id trap_date
13212 2013-03-16 11926 2014-06-26
13213 2013-03-16 11926 2013-07-23
13214 2013-03-16 11926 2015-06-01
13212 2013-03-16 11926 2014-06-26
11926 2010-04-08 10422 2013-01-23
11926 2010-04-08 10422 2013-02-01
11926 2010-04-08 10422 2013-03-08
11926 2010-04-08 10422 2013-03-12
11926 2010-04-08 10422 2013-04-23
11926 2010-04-08 10422 2013-05-01
11926 2010-04-08 10422 2013-08-23
11926 2010-04-08 10422 2013-09-01
11926 2010-04-08 10422 2013-10-23
11926 2010-04-08 10422 2013-12-01
I have a column called mom_id and these individuals also show up in the individual_id column.
I'd like to remove any trap_date records that occur - 35 days or + 70 days from the born date for a mom_id, only if she also shows up in the individual_id column.
So, in this example, I'd like to remove all trap_date records/rows that are between February 9, 2013 (2013-02-09) and May 25, 2013 (2013-05-25) because the born date for mom_id 11926 is March 16, 2013 (2013-03-16).
Desired result:
individual_id born mom_id trap_date
13212 2013-03-16 11926 2014-06-26
13213 2013-03-16 11926 2013-07-23
13214 2013-03-16 11926 2015-06-01
13212 2013-03-16 11926 2014-06-26
11926 2010-04-08 10422 2013-01-23
11926 2010-04-08 10422 2013-02-01
11926 2010-04-08 10422 2013-08-23
11926 2010-04-08 10422 2013-09-01
11926 2010-04-08 10422 2013-10-23
11926 2010-04-08 10422 2013-12-01
A dplyr solution would be appreciated, but I'd appreciate any help at this point!
mom_id11926 is 2010-04-08 not 2013-03-16 which is the born date formom_id19262, isn't it? The ids look confusingly similar.mom_idandindividual_idcolumn, it is confusing to figure out whatborncorresponds to. But,bornis the datemom_idhas to be filtered from (somom_id==11926has aborndate of2013-03-16andmom_id==10422has aborndate of2010-04-08).