Suppose I have the next data:
df <- data.frame(name = c("TO for", "Turnover for people", "HC people",
"Hello world", "beenie man",
"apple", "pears", "TO is"),
number = c(1, 2, 3, 4, 5, 6, 7, 8))
I want to filter the df based on row string pattern, if rows for name column starts with c("TO", "Turnover", "HC") then filter else remove.
The following code gives me a warning message:
library(data.table)
test <- df[df$name %like% c("TO", "Turnover", "HC"), ]
Console output:
Warning message:
In grepl(pattern, vector, ignore.case = ignore.case, fixed = fixed) :
el argumento 'pattern' tiene tiene longitud > 1 y sólo el primer elemento será usado
Expected output should look like this:
# name number
# TO for 1
# Turnover for people 2
# HC people 3
# TO is 8
Is there any other way to accomplish this?