Consider this simple example
mytib <- tibble(mytext = c('hello world',
'nice computer'))
> mytib %>% mutate(myregex1 = str_detect(mytext, 'hello'),
+ myregex2 = str_detect(mytext, 'nice'))
# A tibble: 2 x 3
mytext myregex1 myregex2
<chr> <lgl> <lgl>
1 hello world TRUE FALSE
2 nice computer FALSE TRUE
Essentially, I would like to automate this variable creation and I am not sure what is the most efficient way to do so. The problem is that in my real dataset, I have many regexes I need to use that are stored in a list(myregex1 = 'hello', myregex2 = 'nice')
so creating a mutate for each of them is not good. Is purrr
the solution?
Any ideas? Thanks!!