title: How to efficiently calculate the sum and relative count frequency?
body: <p>I am looking for a one-line dplyr solution for filtering a data.frame on a score and afterwards calculating the relative count frequency.</p>
  <p>The classic R solution would be the following:</p>
  <pre><code>daf &lt;- data.frame(score=c(1:40),count=sample(1:1000,40,replace=T))
  select &lt;- daf$score &gt;= 30
  res &lt;- c(sum(daf$count[select]),sum(daf$count[select])/sum(daf$count))
  </code></pre>
  <p>My first dplyr solution duplicates results:</p>
  <pre><code>daf %&gt;% 
    mutate(total=sum(count)) %&gt;% 
    filter(score &gt;= 30) %&gt;% 
    summarise(
      sum_count=sum(count),
      sum_rel=sum(count)/total
    )
  </code></pre>
  <p>Any better ideas for the dplyr code ?</p>