0

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.

Bileobio
  • 121
  • 8
  • 1
    Hi. Welcome to SO. Please read https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and provide some sample data using `head(dput())` – Lennyy Jun 28 '18 at 06:01
  • you can use `merge` and filter based on `rank` – SatZ Jun 28 '18 at 06:52

1 Answers1

0

you probably want to install the install.packages("survival") and the neardate function within it to solve your problem. It has a good example in the documentation

e.matt
  • 836
  • 1
  • 5
  • 12