how to remove multiple rows that match more than 1 pattern in R?

Viewed 155

Hello I'm trying to remove rows that match more than 1 pattern using grepl this is what I tried:

custom_BGCs[!grepl(c("Chloroflexota","Desulfobacterota_D",
                     "Gemmatimonadota"),custom_BGCs$Phylum),]

on this fashion only "Chloroflexota" rows are removed with a warning message that only rows with the first specified pattern are removed.

Warning message: In grepl(c("Chloroflexota", "Desulfobacterota_D", "Gemmatimonadota", : the argument 'pattern' has a length > 1 and only he first element will be used

How can I remove the other ones?

Thanks for your time :)

1 Answers

grep/grepl is not vectorized for pattern. Use | to combine them into a single string

custom_BGCs[!grepl(paste(c("Chloroflexota","Desulfobacterota_D",
                     "Gemmatimonadota"), collapse = "|"),custom_BGCs$Phylum),]
Related