title: When counting unique factors in a data frame, how do I retain a value from another vector?
body: <p>The data from my data frame "lotsadates" looks like this:</p>
  
  <pre><code>&gt;Date
  
  1 2012-09-26
  2 2012-09-26
  3 2012-09-26
  4 2012-09-27
  5 2012-09-28
  6 2012-09-28
  </code></pre>
  
  <p>There is a day_of_week vector of the same length:<br /></p>
  
  <pre><code>&gt; day_of_week
  
  1 3
  2 3
  3 3
  4 4
  5 5
  6 5
  </code></pre>
  
  <p>I am using the following to count the number of observations by date:<br/></p>
  
  <pre><code>ndist &lt;-tapply(1:NROW(lotsadates), 
                 lotsadates$Date, 
                 function(x) length(unique(x)))
  </code></pre>
  
  <p>So ndist looks like this:<br /></p>
  
  <blockquote>
    <p>Obs / Date / ndist<br > 
    1 / 2012-09-26 / 3<br/>
    2 / 2012-09-27 / 1<br/>
    3 / 2012-09-28 / 2<br /></p>
  </blockquote>
  
  <p>But I want ndist to look like this:</p>
  
  <blockquote>
    <p>Date / ndist / day_of_week <br > 
    1 / 2012-09-26 / 3 / 3<br/>
    2 / 2012-09-27 / 1 / 4<br />
    3 / 2012-09-28 / 2 / 5<br /></p>
  </blockquote>
  
  <p>I think there is a fairly simple solution but I can't figure it out.  Your suggestions are much appreciated!</p>