我有兩組數據:尋找最匹配的時間爲每一個病人
第一組:
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)
另一組數據:
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)
我要創建添加一列到第一個數據集,使得對於每個患者的每個最後一行,它顯示最接近到達時間的可用插槽:
個結果將是:我怎麼能在R.實現這個
patient arrival lastRow availableSlot
A 11:00
A 11:00 Yes 11:15
B 13:00
B 13:00 Yes 12:55
C 14:00
C 14:00
C 14:00
C 14:00 Yes 14:00
希望如果任何人都可以告訴我
你可能需要將自己列與小時Date類第一 – Cath
所以這個轉換工作?合併(data1,data2 [!(data2 $ patient),],by ='patient')'假設您的'data2'是由'arrival'命令的 – Sotos
@Sotos不,那真是太幸運了。 OP表示「最接近」,這恰好與第一次一致。 – Frank