title: compute means of a group by factor
body: <p>Is there a way that this can be improved, or done more simply?</p>
  
  <pre><code>means.by&lt;-function(data,INDEX){
    b&lt;-by(data,INDEX,function(d)apply(d,2,mean))
    return(structure(
      t(matrix(unlist(b),nrow=length(b[[1]]))),
        dimnames=list(names(b),col.names=names(b[[1]]))
    ))
  }
  </code></pre>
  
  <p>The idea is the same as a SAS MEANS BY statement.  The function 'means.by' takes a data.frame and an indexing variable and computes the mean over the columns of the data.frame for each set of rows corresponding to the unique values of INDEX and returns a new data frame with with the row names the unique values of INDEX.</p>
  
  <p>I'm sure there must be a better way to do this in R but I couldn't think of anything.</p>