title: Summary statistics by two or more factor variables?
body: <p>This is best illustrated with an example</p>
  
  <pre><code>str(mtcars)
  mtcars$gear &lt;- factor(mtcars$gear, labels=c("three","four","five"))
  mtcars$cyl &lt;- factor(mtcars$cyl, labels=c("four","six","eight"))
  mtcars$am &lt;- factor(mtcars$am, labels=c("manual","auto")
  str(mtcars)
  tapply(mtcars$mpg, mtcars$gear, sum)
  </code></pre>
  
  <p>That gives me the summed mpg per gear. But say I wanted a 3x3 table with gear across the top and cyl down the side, and 9 cells with the bivariate sums in, how would I get that 'smartly'.</p>
  
  <p>I could go.</p>
  
  <pre><code>tapply(mtcars$mpg[mtcars$cyl=="four"], mtcars$gear[mtcars$cyl=="four"], sum)
  tapply(mtcars$mpg[mtcars$cyl=="six"], mtcars$gear[mtcars$cyl=="six"], sum)
  tapply(mtcars$mpg[mtcars$cyl=="eight"], mtcars$gear[mtcars$cyl=="eight"], sum)
  </code></pre>
  
  <p>This seems cumbersome.</p>
  
  <p>Then how would I bring a 3rd variable in the mix?</p>
  
  <p>This is somewhat in the space I'm thinking about.
  <a href="https://stackoverflow.com/questions/5714658/summary-statistics-using-ddply">Summary statistics using ddply</a></p>
  
  <p><strong>update</strong> This gets me there, but it's not pretty.</p>
  
  <pre><code>aggregate(mpg ~ am+cyl+gear, mtcars,sum)
  </code></pre>
  
  <p>Cheers</p>