0
> head(ordereddf,20)
    patient_id day_given antibiotic_type route
 1:          1         2   ciprofloxacin    IV
 2:          1         4   ciprofloxacin    IV
 3:          1         6   ciprofloxacin    IV
 4:          1         7     doxycycline    IV
 5:          1         9     doxycycline    IV
 6:          1        15      penicillin    IV
 7:          1        16     doxycycline    IV
 8:          1        18   ciprofloxacin    IV
 9:          8         1     doxycycline    PO
10:          8         2      penicillin    IV
11:          8         3     doxycycline    IV
12:          8         6     doxycycline    PO
13:          8         8      penicillin    PO
14:          8        12      penicillin    IV
15:          9         8     doxycycline    IV
16:          9        12     doxycycline    PO
17:         12         4     doxycycline    PO
18:         12         9     doxycycline    IV
19:         16         1     doxycycline    IV
20:         16         4     amoxicillin    IV

I want to extract values that last day which antibiotic was given i.e. antibiotic-name in rows 8,14,16,18,20

Ben
  • 28,684
  • 5
  • 23
  • 45
  • Please make your code more accessible. It would help if you provided the data. – PLY Nov 19 '20 at 20:35
  • This may be helpful: https://stackoverflow.com/questions/31528981/select-first-and-last-row-from-grouped-data or this: https://stackoverflow.com/questions/53620750/get-last-row-of-each-group-in-r – Ben Nov 19 '20 at 21:03

0 Answers0