title: Calculating mean values based on two different groupings in a data frame
body: <p>I would like calculate mean values based on two different groupings in my data frame. 
  An example data set is:</p>
  
  <pre><code>&gt; data
       age Year Length
  [1,]   3 2004   23.2
  [2,]   3 2004   27.6
  [3,]   3 2005   25.4
  [4,]   3 2005   22.2
  [5,]   4 2004   37.6
  [6,]   4 2004   31.3
  [7,]   4 2005   29.9
  [8,]   4 2005   30.1
  </code></pre>
  
  <p>So far, I have used the ddply function to calculate means within one age grouping. To do this I've created an index to sort all of the three year old data and then found the means of length within Year. </p>
  
  <pre><code>logical3=(mydata$Age ==3)
  mydata3= mydata[logical3,]
  mean_values_3 &lt;- ddply(mydata3, "Year", transform, grp.mean.values=mean(Length))
  </code></pre>
  
  <p>I'd like to make the process faster and less clunky by calculating means without sorting by age first. </p>
  
  <p>Is there a way to 1) find mean values based upon more than 1 groups-This grouping does not need to be done sequentially- and 2) how can I get the means to output into a separate data frame and not append to the working one. </p>