title: Using dplyr and stringr to replace all values starts with
body: <p>my df</p>
  
  <pre><code>&gt; df &lt;- data.frame(food = c("fruit banana", "fruit apple", "fruit grape", "bread", "meat"), sold = rnorm(5, 100))
  &gt;   df
            food      sold
  1 fruit banana  99.47171
  2  fruit apple  99.40878
  3  fruit grape  99.28727
  4        bread  99.15934
  5         meat 100.53438
  </code></pre>
  
  <p>Now I want to replace all values in food that starts with "fruit" and then group by food and summarise sold with sum sold. </p>
  
  <pre><code>&gt; df %&gt;%
  +     mutate(food = replace(food, str_detect(food, "fruit"), "fruit")) %&gt;% 
  +     group_by(food) %&gt;% 
  +     summarise(sold = sum(sold))
  Source: local data frame [3 x 2]
  
      food      sold
    (fctr)     (dbl)
  1  bread  99.15934
  2   meat 100.53438
  3     NA 298.16776
  </code></pre>
  
  <p>Why is this command not working? It gives me NA instead of fruit?  </p>