0

I have the following dataset

df =
id medication_code medication_date
1  A               2000-01-01
1  A               2000-01-08        
1  A               2000-01-30
1  B               2000-01-08
1  B               2000-01-30
2  A               2000-01-01
2  A               2000-01-15
2  B               2000-01-09
2  B               2000-01-10
2  B               2000-01-11

I would like to have the first and last observation per individual per medication such as:

df =
id medication_code date_first date_last
1  A               2000-01-01 2000-01-30
1  B               2000-01-08 2000-01-30
2  A               2000-01-01 2000-01-15
2  B               2000-01-09 2000-01-11

note that other examples similar to this focus on the mean or median within the grouped variables.

Economist_Ayahuasca
  • 1,648
  • 24
  • 33

0 Answers0