title: converting summary created using 'by' to data.frame
body: <pre><code>df1=data.frame(c(2,1,2),c(1,2,3,4,5,6),seq(141,170)) #create data.frame
  names(df1) = c("gender","age","height") #column names
  df1$gender &lt;- factor(df1$gender,
  levels=c(1,2),
  labels=c("female","male")) #gives levels and labels to gender
  df1$age &lt;- factor(df1$age,
  levels=c(1,2,3,4,5,6),
  labels=c("16-24","25-34","35-44","45-54","55-64","65+")) # gives levels and labels to age groups
  </code></pre>
  
  <p>I am looking to produce a summary of the height values subsetted by gender and then age.</p>
  
  <p>Using the <code>subset</code> and <code>by</code> functions as provides the output I want:</p>
  
  <pre><code>females&lt;-subset(df1,df1$gender==1) #subsetting by gender
  males&lt;-subset(df1,df1$gender==2)
  
  foutput=by(females$height,females$age,summary) #producing summary subsetted by age
  moutput=by(males$height,males$age,summary)
  </code></pre>
  
  <p>However I require it to be in a data.frame so that I can export these results alongside frequency tables using XLconnect. </p>
  
  <p>Is there an way to convert the output to a data.frame or an elegant alternative, possibly using plyr?</p>