title: R -- Logical grep on multiple variables within data frame
body: <p>I am interested in performing a string search using logical grep (grepl) in R, with multiple string patterns, and would like to apply this function to several variables (columns) in my data frame.  I believe that one of the apply functions is going to be well-suited to this task, but I am not entirely sure how to get it to work correctly.  Please find an example (toy) included below:</p>
  
  <pre><code>v.grepl &lt;- Vectorize(grepl)
  pattern &lt;- "^330|^334|^335|^343|^359|^740|^741|^742"
  data &lt;- structure(list(recnum = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
                     pr1_3 = c("334", "550", "600", "812", "748", "968", "123", "456", "789", "821"),
                     pr2_3 = c("350", "222", "367", "", "", "", "", "", "", ""),
                     pr3_3 = c("857", "", "", "", "", "", "", "", "", ""), 
                     pr4_3 = c("359", "740", "336", "400", "", "", "", "", "", ""),
                     pr5_3 = c("800", "", "", "", "", "", "", "", "", "")),
                .Names = c("recnum", "pr1_3", "pr2_3", "pr3_3", "pr4_3", "pr5_3"),
                row.names = c(1L, 2L, 3L,4L, 5L, 6L, 7L, 8L, 9L, 10L),
                class = "data.frame")
  
  data$check &lt;- apply(data, 2, v.grepl(pattern, data[c('pr1_3', 'pr2_3', 'pr3_3', 'pr4_3', 'pr5_3')]))
  </code></pre>
  
  <p>The last line of code throws the following error:</p>
  
  <pre><code>Error in match.fun(FUN) : 
  'v.grepl(pattern, data[c("pr1_3", "pr2_3", "pr3_3", "pr4_3", "pr5_3")])' is not a function, character or symbol
  </code></pre>
  
  <p>Does anyone have any ideas for how to fix this code so that it adds a new variable within the <code>data</code> dataframe (called <code>check</code>) that flags whether each row has a <code>pr1_3</code> through <code>pr5_3</code> that matches the strings included in <code>pattern</code>?</p>
  
  <p>Thanks!</p>