Detect multiple strings with dplyr and stringr
I'm trying to combine dplyr and stringr to detect multiple patterns in a dataframe. I want to use dplyr as I want to test a number of different columns. Here's some sample data: test.data <- data.frame(item = c("Apple", "Bear", "Orange", "Pear", "Two Apples")) fruit <- c("Apple", "Orange", "Pear") test.data item 1 Apple 2 Bear 3 Orange 4 Pear 5 Two Apples What I would like to use is something like: test.data <- test.data %>% mutate(is.fruit = str_detect(item, fruit)) and receive item is.fruit 1 Apple 1 2 Bear 0 3 Orange 1 4 Pear 1 5 Two Apples 1 A very simple test works > str_detect("Apple",