strengejacke / sjmisc

Data transformation and utility functions for R

Home Page:https://strengejacke.github.io/sjmisc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use str_contains for dataframe?

bes827 opened this issue · comments

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

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)

thanks you. this works. do I have to keep switch = TRUE in this case?