title: How to group by counts in R?
body: <p>How to count the number of cases (similar to COUNT . . . GROUP BY in sql) ? </p>
  
  <p>Here is my code that works </p>
  
  <pre><code>library(magrittr) 
  library(dplyr)
  df &lt;- data.frame(dose=c("A", "B", "C","D", "E", "B","B", "E", "A","C", "C", "B"),
                   len=c(4.2, 10, 29.5,4.2, 10, 29.5,4.2, 10, 29.5,4.2, 10, 29.5))
  mt_mean &lt;-   df %&gt;% group_by(dose) %&gt;% summarise(avg_count = sum(len) )  
  mt_mean 
  </code></pre>
  
  <p><strong>But I want the counts NOT the sum</strong> </p>
  
  <p>So when I change <code>avg_count = sum(len)</code> to <code>avg_count = count(len)</code> 
  The following error is thrown </p>
  
  <pre><code>Error in summarise_impl(.data, dots) : 
    Evaluation error: no applicable method for 'groups' applied to an object of class "c('double', 'numeric')". 
  </code></pre>
  
  <p>How to group by counts in R? </p>