I have two data frames. One data frame is called Measurements
and has 500 rows. The columns are PatientID
, Value
and M_Date
. The other data frame is called Patients
and has 80 rows and the columns are PatientID
, P_Date
.
Each patient ID in Patients is unique. For each row in Patients
, I want to look at the set of measurements in Measurements
with the same PatientID
(there are maybe 6-7 per patient).
From this set of measurements, I want to identify the one with M_Date
closest to P_Date
. I want to append this value to Patients
in a new column. How do I do this? I tried using ddplyr
but can't figure out how to access two data frames at once within this function.