title: Create a new column based on matched string in another column using grep function
body: <p>I'm trying to use grep function to create a new column based on matched string (no match = 0, match =1) but not getting the expected results </p>
  
  <pre><code>#my data
  data&lt;- data.frame(col1 = c("name","no_match","123","0.19","rand?m","also_no_match"))
  
  #string to match
  match_txt &lt;- "[0-9]\\.[0-9][0-9]|name|name2|wh??|[0-9]|\\?"  #used "|" to match multiple strings
  
  #create the new column using for loop
  for (i in 1:nrow(data))
    {
  data$col2[i] &lt;- grep(match_txt , data$col1[i])
  }
  
  # I get the error below:
  # Error in data$col2[i] &lt;- grep(match_txt, data$col1[i],  ignore.case = TRUE) : replacement has length zero
  
  #this is expected correct results:
  expected_data &lt;- data.frame(col1 = c("name","no_match","123","0.19","rand?m","also_no_match"),
                              col2 = c(1,0,1,1,1,0))
  </code></pre>