title: group by count when count is zero in r
body: <p>I use aggregate function to get count by group.  The aggregate function only returns count for groups if count > 0.  This is what I have</p>
  
  <pre><code>dt &lt;- data.frame(
  n  = c(1,2,3,4,5,6),
  id = c('A','A','A','B','B','B'),
  group = c("x","x","y","x","x","x")) 
  </code></pre>
  
  <p>applying the aggregate function</p>
  
  <pre><code>my.count &lt;- aggregate(n ~ id+group, dt, length)
  </code></pre>
  
  <p>now see the results</p>
  
  <pre><code>my.count[order(my.count$id),]
  </code></pre>
  
  <p>I get following</p>
  
  <pre><code>id group   n
  1  A     x 2
  3  A     y 1
  2  B     x 3
  </code></pre>
  
  <p>I need the following (the last row has zero that i need)</p>
  
  <pre><code>id group   n
  1  A     x 2
  3  A     y 1
  2  B     x 3
  4  B     y 0
  </code></pre>
  
  <p>thanks for you help in in advance</p>