title: counting unique factors in r
body: <p>I would like to know the number of unique dams which gave birth on each of the birth dates recorded. My data frame is similar to this one:</p>
  
  <pre><code>dam &lt;- c("2A11","2A11","2A12","2A12","2A12","4D23","4D23","1X23")
  bdate &lt;- c("2009-10-01","2009-10-01","2009-10-01","2009-10-01",
             "2009-10-01","2009-10-03","2009-10-03","2009-10-03")
  mydf &lt;- data.frame(dam,bdate)
  mydf
  #    dam      bdate
  # 1 2A11 2009-10-01
  # 2 2A11 2009-10-01
  # 3 2A12 2009-10-01
  # 4 2A12 2009-10-01
  # 5 2A12 2009-10-01
  # 6 4D23 2009-10-03
  # 7 4D23 2009-10-03
  # 8 1X23 2009-10-03
  </code></pre>
  
  <p>I used <code>aggregate(dam ~ bdate, data=mydf, FUN=length)</code> but it counts all the dams that gave birth on a particular date</p>
  
  <pre><code>bdate dam
  1 2009-10-01   5
  2 2009-10-03   3
  </code></pre>
  
  <p>Instead, I need to have something like this:</p>
  
  <pre><code>mydf2
    bdate      dam
  1 2009-10-01  2
  2 2009-10-03  2
  </code></pre>
  
  <p>Your help is very much appreciated!</p>