0

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!

  • Try using regular expressions. I believe something like `grepl("unassigned", taxon)` should give you what you're looking for – Mike H. Feb 05 '18 at 19:06

2 Answers2

1

A grepl answer:

Newdata <- mydata %>%
  filter(!grepl(".*unassigned.*",taxon))
jasbner
  • 2,253
  • 12
  • 24
0

Try something like this:

library(tidyverse)
library(stringr)
# Create sample data
test <- c("hello", "world", "unassigned", "unassigned2", "unassigned3")
# Create data frame
df <- data.frame(test)
# Filter dataframe named "df" at column "test" for strings containing "unassigned"
df %>% filter(str_detect(test, "unassigned"))

This outputs

         test
1  unassigned
2 unassigned2
3 unassigned3
Celi Manu
  • 371
  • 2
  • 7
  • 19