title: Count number of rows per group and add result to original data frame
body: <p>Say I have a <code>data.frame</code> object:</p>
  
  <pre><code>df &lt;- data.frame(name=c('black','black','black','red','red'),
                   type=c('chair','chair','sofa','sofa','plate'),
                   num=c(4,5,12,4,3))
  </code></pre>
  
  <p>Now I want to count the number of rows (observations) of for each combination of <code>name</code> and <code>type</code>. This can be done like so:</p>
  
  <pre><code>table(df[ , c("name","type")])
  </code></pre>
  
  <p>or possibly also with <code>plyr</code>, (though I am not sure how).</p>
  
  <p>However, how do I get the results incorporated into the original data frame?  So that the results will look like this:</p>
  
  <pre><code>df
  #    name  type num count
  # 1 black chair   4     2
  # 2 black chair   5     2
  # 3 black  sofa  12     1
  # 4   red  sofa   4     1
  # 5   red plate   3     1
  </code></pre>
  
  <p>where <code>count</code> now stores the results from the aggregation.</p>
  
  <p>A solution with <code>plyr</code> could be interesting to learn as well, though I would like to see how this is done with base R.</p>