title: In R, how do I count unique values of a factor based on another factor?
body: <p>I have data which could be described as...</p>
  
  <pre><code>factor1 &lt;- c(rep("A", 5), rep("B", 5), rep("C", 5))
  factor2 &lt;- c("title1", "title1", "title2", "title2", "title3",
               "title4", "title4", "title4", "title4", "title5",
               "title6", "title6", "title6", "title6", "title6")
  
  df &lt;- data.frame(factor1, factor2)
  </code></pre>
  
  <p>...and what I want is a count of how many unique values in <code>factor2</code> occur at each level of <code>factor1</code>. So my expected output in this case would be:</p>
  
  <pre><code>A   3
  B   2
  C   1
  </code></pre>
  
  <p>What is the most efficient (because Shiny will later be involved) function to do this? My various attempts at <code>table</code> or <code>xtabs</code> or <code>aggregate</code> are being foiled by the fact that both columns are factors.</p>