title: filtering within the summarise function of dplyr
body: <p>I am struggling a little with <code>dplyr</code> because I want to do two things at one and wonder if it is possible.</p>
  
  <p>I want to calculate the mean of values and at the same time the mean for the values which have a specific value in an other column.</p>
  
  <pre><code>library(dplyr)
  set.seed(1234)
  df &lt;- data.frame(id=rep(1:10, each=14),
                   tp=letters[1:14],
                   value_type=sample(LETTERS[1:3], 140, replace=TRUE),
                   values=runif(140))
  
  df %&gt;%
    group_by(id, tp) %&gt;%
    summarise(
      all_mean=mean(values),
      A_mean=mean(values), # Only the values with value_type A
      value_count=sum(value_type == 'A')
    )
  </code></pre>
  
  <p>So the <code>A_mean</code> column should calculate the mean of <code>values</code> where <code>value_count == 'A'</code>.</p>
  
  <p>I would normally do two separate commands and merge the results later, but I guess there is a more handy way and I just don't get it.</p>
  
  <p>Thanks in advance.</p>