Q:

grepl pattern length warning

I have two columns in a data.frame x called "preferred_cat" and "var_nm". I want to create a third column called "preferred_tag" with value either 1 or 0. 
1- if preferred_cat(for ex qq) is subset of var_nm (for ex jdsajqq) or
0- if preferred_cat(for ex qq) is not subset of var_nm (for ex qdsajq)
x <- x %>% mutate(preferred_tag=ifelse(grepl(preferred_cat,var_nm,fixed=TRUE),1,0))

However I am getting this warning:
Warning message:
In grepl(preferred_cat, var_nm, fixed = TRUE) :
  argument 'pattern' has length > 1 and only the first element will be used

What is does this warning mean, and how can I avoid it?

A:

grepl won't take a vector of strings. You could use map2 from purrr
First create a new function which returns a 1 if there is a substring, 0 otherwise.
new_func <- function(x,y){
if(grepl(x,y,fixed=TRUE)){
  check <- 1
} else{
  check <- 0
}
check
}

Now map2 this function to each pair of strings:
library(purrr)
x <- x %>% 
     mutate(preferred_tag=map2(referred_cat, var_nm, new_func))

