title: Mean of variable by two factors
body: <p>I have the following data:</p>
  
  <pre><code>a &lt;- c(1,1,1,1,2,2,2,2)
  b &lt;- c(2,4,6,8,2,3,4,1)
  c &lt;- factor(c("A","B","A","B","A","B","A","B"))
  df &lt;- data.frame(
      sp=a,
      length=b,
      method=c)
  </code></pre>
  
  <p>I can use the following to get a count of the number of samples of each species by method:</p>
  
  <pre><code>n &lt;- with(df,tapply(sp,method,function(x) count(x)))
  </code></pre>
  
  <p>How do I also get the mean length by method for each species?</p>