title: Finding closest matching time for each patient
body: <p>I have two sets of data:</p>
  
  <p>First set:</p>
  
  <pre><code> patient&lt;-c("A","A","B","B","C","C","C","C")
   arrival&lt;-c("11:00","11:00","13:00","13:00","14:00","14:00","14:00","14:00")
   lastRow&lt;-c("","Yes","","Yes","","","","Yes")
  
   data1&lt;-data.frame(patient,arrival,lastRow)
  </code></pre>
  
  <p>Another set of data:</p>
  
  <pre><code> patient&lt;-c("A","A","A","A","B","B","B","C","C","C")
   availableSlot&lt;-c("11:15","11:35","11:45","11:55","12:55","13:55","14:00","14:00","14:10","17:00")
  
   data2&lt;-data.frame(patient, availableSlot)
  </code></pre>
  
  <p>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 the arrival time:</p>
  
  <p>The results would be:</p>
  
  <pre><code>  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
  </code></pre>
  
  <p>Would appreciate if anyone can tell me how I can implement this in R. </p>