Hi there,
I have a data frame called drugs_study this has three columns called formulation_code, approved_name, and date. The formulation_code includes the type of formulation of rug (cream, tablet etc), the approved_name is the drug name (aspirin etc).
I would like to filter in(and exclude all other rows) all of some of the formulations from the formulation_code (for example all tablets) as well as some selected formulations for specific drug names (for example aspirin capsules). All the rest of the data frame should then be excluded from the final new tibble which is called drugs_filtered.
I have tried
drugs_filtered <-
drugs_study %>%
filter(
any(formulation_code == "TABLETS") |
any(formulation_code == "CAPSULES" & approved_name == "ASPIRIN")
But that doesn't actually seem to exclude all the other rows. I tried select() also but could not get that to work. Does anyone have any ideas?
Many thanks,
Clare