I have two df's: maindf
and list
.
ID <- c(1, 1, 1, 1, 5, 5)
SURVEY_DATE <- c("1997-08-01", "1998-08-20", "1998-11-20", "2000-12-13", "1998-05-02", "1998-12-25")
SURVEY_DATE <- as.Date(SURVEY_DATE)
maindf <- data.frame(ID, SURVEY_DATE)
maindf
ID <- c(1, 1, 1, 1, 5, 5)
ASSIGN_DATE <- c(1997, 1998, 1999, 2000, 1997, 1998)
TIME1 <- c("1997-07-23", "1998-11-17", "1999-12-15", "2000-12-11", "1998-04-07", "1998-12-06")
TIME1 <- as.Date(TIME1)
TIME2 <- c("1998-11-17", "1999-12-15", "2000-12-11", "2001-12-30", "1998-12-06", "1999-11-28")
TIME2 <- as.Date(TIME2)
list <- data.frame(ID, ASSIGN_DATE, TIME1, TIME2)
list
The maindf
has a SURVEY_DATE
field. This field needs to check in the list
to see if it falls within TIME1
and TIME2
by ID
. If it does, I would like to pull the ASSIGN_DATE
into the maindf
.
The final product should look like:
ID SURVEY_DATE ASSIGN_DATE
1 1 1997-08-01 1997
2 1 1998-08-20 1997
3 1 1998-11-20 1998
4 1 2000-12-13 2000
5 5 1998-05-02 1997
6 5 1998-12-25 1998
I know this is very similar to this post and this post, but I'm having some trouble with pulling a field over by ID
.