Finding closest matching time for each patient
I have two sets of data: First set: patient<-c("A","A","B","B","C","C","C","C") arrival<-c("11:00","11:00","13:00","13:00","14:00","14:00","14:00","14:00") lastRow<-c("","Yes","","Yes","","","","Yes") data1<-data.frame(patient,arrival,lastRow) Another set of data: patient<-c("A","A","A","A","B","B","B","C","C","C") availableSlot<-c("11:15","11:35","11:45","11:55","12:55","13:55","14:00","14:00","14:10","17:00") data2<-data.frame(patient, availableSlot) I want to create add a column to the first dataset such that for each last row of each patient, it shows the available slot that is closest to