title: How can I collapse a dataframe by some variables, taking mean across others
body: <p>I need to summarize a data frame by some variables, ignoring the others. This is sometimes referred to as collapsing. E.g. if I have a dataframe like this:  </p>
  
  <pre><code>Widget Type Energy  
  egg 1 20  
  egg 2 30  
  jap 3 50  
  jap 1 60
  </code></pre>
  
  <p>Then collapsing by Widget, with Energy the dependent variable,   Energy~Widget, would yield  </p>
  
  <pre><code>Widget Energy  
  egg  25  
  jap  55  
  </code></pre>
  
  <p>In Excel the closest functionality might be "Pivot tables" and I've worked out how to do it in python ( <a href="http://alexholcombe.wordpress.com/2009/01/26/summarizing-data-by-combinations-of-variables-with-python/" rel="noreferrer">http://alexholcombe.wordpress.com/2009/01/26/summarizing-data-by-combinations-of-variables-with-python/</a>), and here's an example with R using doBy library to do something very related ( <a href="http://www.mail-archive.com/r-help@r-project.org/msg02643.html" rel="noreferrer">http://www.mail-archive.com/r-help@r-project.org/msg02643.html</a>), but is there an easy way to do the above?  And even better is there anything built into the ggplot2 library to create plots that collapse across some variables?</p>