I am trying to filter targeted tissues ("heart", "muscle", "kidney", "liver")
in my df which is pasted below and list name of species that have all of the targeted tissues.
my df:
Species,Tissue
Human,Kr_liver_2
Human,Heart
Human,Liver_556
Human,Kr_Kidney_2
Human,Kr_Muscle_2
Human,Kr_Brain_2
Mouse,Brain
Mouse,Kr_liver_3
Mouse,Kr_liver_5
Mouse,Kr_liver_27
I try the approach below but I got an empty output, however, the desired output based on the df above should be Human because it has all of the targetted tissues.
Tissue_check <- df %>%
group_by(Species) %>%
filter(all(grepl(paste(target_tissues, collapse = "|"), tolower(Tissue)))) %>%
pull(Species) %>%
unique()
How can I achieve this?