Search code examples
rselectfilterdplyrcontain

Removing values that contain a string using dplyr (R)


My current code removes only the values that have the exact value of "unassigned", whereas I want it to remove any value that contains "unassigned".

Here's my code

Newdata <- mydata %>%
  filter(taxon !="unassigned")

The column I'm looking to remove any "unassigned" values from is called taxon.

Thanks!


Solution

  • A grepl answer:

    Newdata <- mydata %>%
      filter(!grepl(".*unassigned.*",taxon))