Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use str_contains for dataframe? #141

Open
bes827 opened this issue Sep 26, 2020 · 2 comments
Open

Use str_contains for dataframe? #141

bes827 opened this issue Sep 26, 2020 · 2 comments

Comments

@bes827
Copy link

bes827 commented Sep 26, 2020

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
Copy link
Owner

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
Copy link
Author

bes827 commented Oct 31, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants