I'm not sure how you intend to handle these. One way is to simply filter them out
suppressPackageStartupMessages({
library(dplyr)
library(stringr)
})
pattern <- "[:punct:]"
control_otu <- data.frame(phyla = c("[Thermi]", "Actinobacteria", "Bacteroides", "Chlamydiae", "Chloroflexi", "Cyanobacteria", "Firmicutes", "Planctomyces", "Proteobacteria", "Tenericutes", "TM6", "Verrucomicrobia"))
control_otu %>% mutate(phyla = str_remove_all(phyla, pattern)) -> control_otu
the_others <- c("Thermi", "Chlamydiae", "Chloroflexi", "Cyanobacteria", "Verrucomicrobia")
control_otu %>% filter(!(phyla %in% the_others))
#> phyla
#> 1 Actinobacteria
#> 2 Bacteroides
#> 3 Firmicutes
#> 4 Planctomyces
#> 5 Proteobacteria
#> 6 Tenericutes
#> 7 TM6
Created on 2020-11-02 by the reprex package (v0.3.0.9001)
If you want to retain the records, but just classify those taxa to "Other"
suppressPackageStartupMessages({
library(dplyr)
library(stringr)
})
pattern <- "[:punct:]"
control_otu <- data.frame(phyla = c("[Thermi]", "Actinobacteria", "Bacteroides", "Chlamydiae", "Chloroflexi", "Cyanobacteria", "Firmicutes", "Planctomyces", "Proteobacteria", "Tenericutes", "TM6", "Verrucomicrobia"))
control_otu %>% mutate(phyla = str_remove_all(phyla, pattern)) -> control_otu
the_others <- c("Thermi", "Chlamydiae", "Chloroflexi", "Cyanobacteria", "Verrucomicrobia")
control_otu %>% mutate(phyla = ifelse(phyla %in% the_others,"Other",phyla))
#> phyla
#> 1 Other
#> 2 Actinobacteria
#> 3 Bacteroides
#> 4 Other
#> 5 Other
#> 6 Other
#> 7 Firmicutes
#> 8 Planctomyces
#> 9 Proteobacteria
#> 10 Tenericutes
#> 11 TM6
#> 12 Other
Created on 2020-11-02 by the reprex package (v0.3.0.9001)