I am trying to determine if multiple dates in one data frame are within multiple date ranges from another data frame. The dates and date ranges should be compared within each ID. I'd then like to update the data from the first data frame with information from the second data frame. Both data frames can potentially have 0 to multiple records for each ID. For example, df1 might look like this:
UID1 ID Date
1 1 05/12/10
2 1 07/25/11
3 1 07/31/12
4 2 11/04/03
5 2 10/06/04
6 3 10/07/08
7 3 06/16/12
While df2 might look like this (note ID=2 has no records in df2):
UID2 ID StartDate EndDate
1 1 07/22/09 09/13/09
2 1 03/19/10 11/29/10
3 1 05/09/11 09/04/11
4 3 05/18/12 08/15/12
5 3 01/15/13 04/21/13
I would like to end up with a new df1 that looks like this:
UID1 ID Date UID2 InRange DaysSinceStart
1 1 05/12/10 2 TRUE 54
2 1 07/25/11 3 TRUE 77
3 1 07/31/12 NA FALSE NA
4 2 11/04/03 NA FALSE NA
5 2 10/06/04 NA FALSE NA
6 3 10/07/08 NA FALSE NA
7 3 06/16/12 4 TRUE 29
Suggestions?