I have two data frames that I am trying to combine into one master data frame by ID and Date. My issue is that the data frames have some similar and some unique dates. One data frame goes sequentially through the dates but may be missing a day or two at the beginning and/or end, while the other data frame has multiple samples from the same ID and is only sampled every 3 days.
DF1 example:
Nest.ID Date X Y Nest.ID.Date
AMRO_1_ 5/2/20 7 2 AMRO_1_5-02-20
AMRO_1_ 5/3/20 1 5 AMRO_1_5-03-20
AMRO_1_ 5/4/20 7 9 AMRO_1_5-04-20
AMRO_1_ 5/5/20 3 2 AMRO_1_5-05-20
AMRO_1_ 5/6/20 1 3 AMRO_1_5-06-20
DF2 Example
Nest.ID Indiv.ID Date U V Nest.ID.Date
AMRO_1_ A 5/1/20 468 294 AMRO_1_5-01-20
AMRO_1_ B 5/1/20 454 456 AMRO_1_5-01-20
AMRO_1_ C 5/1/20 436 245 AMRO_1_5-01-20
AMRO_1_ A 5/4/20 356 762 AMRO_1_5-04-20
AMRO_1_ B 5/4/20 345 953 AMRO_1_5-04-20
AMRO_1_ C 5/4/20 356 345 AMRO_1_5-04-20
AMRO_1_ A 5/7/20 763 193 AMRO_1_5-07-20
AMRO_1_ B 5/7/20 763 186 AMRO_1_5-07-20
AMRO_1_ C 5/7/20 235 762 AMRO_1_5-07-20
Wanted Outcome:
Nest.ID Date X Y Indiv.ID U V
AMRO_1_ 5/1/20 NA NA A 468 294
AMRO_1_ 5/1/20 NA NA B 454 456
AMRO_1_ 5/1/20 NA NA C 436 245
AMRO_1_ 5/2/20 7 2 NA NA NA
AMRO_1_ 5/3/20 1 5 NA NA NA
AMRO_1_ 5/4/20 7 9 A 356 762
AMRO_1_ 5/4/20 7 9 B 345 953
AMRO_1_ 5/4/20 7 9 C 356 345
AMRO_1_ 5/5/20 3 2 NA NA NA
AMRO_1_ 5/6/20 1 3 NA NA NA
AMRO_1_ 5/7/20 NA NA A 763 193
AMRO_1_ 5/7/20 NA NA B 763 186
AMRO_1_ 5/7/20 NA NA C 235 762
Using a full_join
with keep= TRUE
I can get very close and get a final DF with all the data from DF1 and with NAs where DF2 wasn't sampled, but I cannot figure out how to also include the beginning/end dates that are not in DF1 but in DF2 (so 5/1 and 5/7 in the examples). I suspect this may be due to my "key" of ID.Date, but those are the only variables I can use to keep things in order when merging (in other words, since I have multiple samples per ID, I can't just use ID as my "key").