We could use filter_all
with any_vars
df %>%
filter_all(any_vars(str_detect(str_to_lower(.), "^(bio|15)")))
# Name Code
#1 Biofuel is good 159403
#2 Bioecological is good 161540
#3 Probiotics is good 159883
NOTE: If it is a subset of columns that needs the conditions to apply, use filter_at
If we need to pick any word that start with 'Bio' in a sentence, wrap with word boundary (\b
)
df %>%
filter_all(any_vars(str_detect(str_to_lower(.), "\bbio|^15")))
data
df <- structure(list(Name = structure(c(2L, 1L, 4L, 3L),
.Label = c("Bioecological is good",
"Biofuel is good", "Good is symbiotic", "Probiotics is good"),
class = "factor"),
Code = c(159403, 161540, 159883, 1877447)), class = "data.frame", row.names = c(NA,
-4L))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…