title: Count number of rows within each group
body: <p>I have a dataframe and I would like to count the number of rows within each group. I reguarly use the <code>aggregate</code> function to sum data as follows:</p>
  
  <pre><code>df2 &lt;- aggregate(x ~ Year + Month, data = df1, sum)
  </code></pre>
  
  <p>Now, I would like to count observations but can't seem to find the proper argument for <code>FUN</code>. Intuitively, I thought it would be as follows:</p>
  
  <pre><code>df2 &lt;- aggregate(x ~ Year + Month, data = df1, count)
  </code></pre>
  
  <p>But, no such luck.</p>
  
  <p>Any ideas?</p>
  
  <hr>
  
  <p>Some toy data:</p>
  
  <pre><code>set.seed(2)
  df1 &lt;- data.frame(x = 1:20,
                    Year = sample(2012:2014, 20, replace = TRUE),
                    Month = sample(month.abb[1:3], 20, replace = TRUE))
  </code></pre>