title: Use data.table to count and aggregate / summarize a column
body: <p>I want to count and aggregate(sum) a column in a <code>data.table</code>, and couldn't find the most efficient way to do this.  This seems to be close to what I want <a href="https://stackoverflow.com/questions/16513827/r-summarizing-multiple-columns-with-data-table">R summarizing multiple columns with data.table</a>.</p>
  
  <p>My data:</p>
  
  <pre><code>set.seed(321)
  dat &lt;- data.table(MNTH = c(rep(201501,4), rep(201502,3), rep(201503,5), rep(201504,4)), 
                    VAR = sample(c(0,1), 16, replace=T))
  
  &gt; dat
       MNTH VAR
   1: 201501   1
   2: 201501   1
   3: 201501   0
   4: 201501   0
   5: 201502   0
   6: 201502   0
   7: 201502   0
   8: 201503   0
   9: 201503   0
  10: 201503   1
  11: 201503   1
  12: 201503   0
  13: 201504   1
  14: 201504   0
  15: 201504   1
  16: 201504   0
  </code></pre>
  
  <p>I want to both count and sum <code>VAR</code> by <code>MNTH</code> using data.table. The desired result:</p>
  
  <pre><code>    MNTH COUNT VAR
  1 201501     4   2
  2 201502     3   0
  3 201503     5   2
  4 201504     4   2
  </code></pre>