title: dplyr: Conditional mutate using text (grep?)
body: <p>Is it possible to use text pattern matching with numerical replacement while in dplyr's mutate?</p>
  
  <p>Here's a toy dataset:</p>
  
  <pre><code>library(dplyr)
  df &lt;- data.frame(Group = c("Group1", "Group1", "Group1", "Group1", "Group2", "Group2"), Activity = c("1. First really long response", "2. Second really long response", "1. First really long response", "2. Second really long response", "1. First really long response", "2. Second really long response"))
  </code></pre>
  
  <p>I create a new dataframe with a count of respondents who selected "1. First really long response."</p>
  
  <pre><code>test &lt;- df %&gt;%
    group_by(Group) %&gt;% summarise(
      `Participants` = length(Activity[Activity == "1. First really long response"])
    )
  </code></pre>
  
  <p>That works.</p>
  
  <p>Let's say I want to avoid using the whole response to the variable Activity. (The responses are really quite long.) Is it possible to do something like the following (which obviously doesn't work)? </p>
  
  <pre><code>test &lt;- df %&gt;%
    group_by(Group) %&gt;% summarise(
      `Participants` = ifelse(grepl("1.", Activity), length(Activity)))
  </code></pre>
  
  <p>Something like:</p>
  
  <ol>
  <li>Look in the Activity variable for something that starts with "1." </li>
  <li>If you find it, mark as TRUE.</li>
  <li>Count how many total TRUE's there are in the new Participants variable.</li>
  </ol>