I have the following dataframe:
df <- data.frame(
Code = c("a", "a", "a", "a", "a", "b", "b", "b", "b", "b"),
Inst = c("Yes", "No", "No", "No", "No", "No", "No", "No", "No", "No"),
Date = c(
"2021-01-01", "2021-01-02", "2021-01-03", "2021-01-04", "2021-01-05",
"2021-01-06", "2021-01-06", "2021-01-06", "2021-01-09", "2021-01-10"
)
)
I want to apply dplyr::group_by to the variable Code and filter for specific value "Yes" and for minimum Date, but I want to keep all observations of groups that do not contain the Yes value. I tried filter(any(Inst == "Yes")) but this does not work.
I would like to have this result:
Code Inst Date
a Yes 2021-01-01
b No 2021-01-06
b No 2021-01-06
b No 2021-01-06