title: Count number of rows by group using dplyr
body: <p>I am using the <code>mtcars</code> dataset. I want to find the number of records for a particular combination of data. Something very similar to the <code>count(*)</code> group by clause in SQL. <code>ddply()</code> from <em>plyr</em> is working for me </p>
  
  <pre><code>library(plyr)
  ddply(mtcars, .(cyl,gear),nrow)
  </code></pre>
  
  <p>has output</p>
  
  <pre><code>  cyl gear V1
  1   4    3  1
  2   4    4  8
  3   4    5  2
  4   6    3  2
  5   6    4  4
  6   6    5  1
  7   8    3 12
  8   8    5  2
  </code></pre>
  
  <p>Using this code</p>
  
  <pre><code>library(dplyr)
  g &lt;- group_by(mtcars, cyl, gear)
  summarise(g, length(gear))
  </code></pre>
  
  <p>has output</p>
  
  <pre><code>  length(cyl)
  1          32
  </code></pre>
  
  <p>I found various functions to pass in to <code>summarise()</code> but none seem to work for me. One function I found is <code>sum(G)</code>, which returned</p>
  
  <pre><code>Error in eval(expr, envir, enclos) : object 'G' not found
  </code></pre>
  
  <p>Tried using <code>n()</code>, which returned </p>
  
  <pre><code>Error in n() : This function should not be called directly
  </code></pre>
  
  <p>What am I doing wrong? How can I get <code>group_by()</code> / <code>summarise()</code> to work for me?</p>