I have the following dataframe
df =
id date medication related_medication
1 2017-02-18 A yes
1 2017-02-07 D yes
2 2017-02-18 S yes
2 2017-02-18 F no
3 2017-02-18 A yes
3 2017-02-01 F yes
I want to take only the minimum date on which related medications appeared per id. In the above example we have only indivoduals 1 and 3 with 2 related_medication (sinc this variable take a value yes). For this reason I would love to take the minimum date of when the appear. The resulting table should look like the following:
df =
id date medication related_medication
1 2017-02-07 D yes
2 2017-02-18 S yes
2 2017-02-18 F no
3 2017-02-01 F yes
so far I have tried:
df_final <- df %>%
slice(which.min(date))
but I dont find the way to carry this operation only when a certain condition is met, i.e. related_medication == "yes"
cheers