Use str_contains for dataframe?
bes827 opened this issue · 2 comments
bes827 commented
str_contains is a great function.
is it possible to use for detecting a string in a column in a dataset? is there a way for x to be a variable? eg dataset$variable1, rather than a vector or a string?
thank you
strengejacke commented
dataset$variable1
is a vector, so yes, this should work. You should place the search pattern as first, the column / variable as second argument:
library(sjmisc)
d <- data.frame(v1 = c("def", "abc", "xyz"))
str_contains("abc", d$v1, switch = TRUE)
#> [1] FALSE TRUE FALSE
Created on 2020-10-30 by the reprex package (v0.3.0)
bes827 commented
thanks you. this works. do I have to keep switch = TRUE
in this case?