title: Aggregating multiple dependent measures
body: <p>I need to aggregate over a number of dependent measures (DMs) in R. I found the following discussion here quite useful: </p>
  
  <p><a href="https://stackoverflow.com/questions/9723208/aggregate-multiple-variables-simultaneously.">Aggregate / summarize multiple variables per group (i.e. sum, mean, etc)</a></p>
  
  <p>Based on this, the code below basically does what I need. It gets quite lengthy, however, as the number of DMs increases (I have many DMs):</p>
  
  <pre><code>aggregate(cbind(DM1, DM2, DV3, DM4, DM5 ... DMn) ~ F1 + F2 +
             F3, data = sst2, mean, na.rm=TRUE) 
  </code></pre>
  
  <p>I was therefore wondering if there was a more efficient way of writing the DMs, without having to individually type every one of them. Most DMs of interest are next to one another (i.e. <code>DM3</code>, <code>DM4</code>, <code>DM5</code> etc.), so I was thinking of using something along the lines of <code>cbind(DM1, DM3:DM10, DM14)</code>, but this doesn't seem to work. I also tried generating a list of the relevant column names. Unfortunately this didn't work either:</p>
  
  <pre><code>pr&lt;-colnames(sst2)
  pr2&lt;-pr[pr!="DM2" &amp; pr!="DM11" &amp; pr!="DM12" &amp; pr!="DM13"]
  pr3&lt;-noquote(paste(pr2,collapse=","))
  pp&lt;-aggregate(cbind(pr3) ~ F1 + F2 +
             F3, data = sst2, mean, na.rm=TRUE) 
  </code></pre>
  
  <p>Any suggestions on how to efficiently include a large number of DMs in the aggregate function (or other related functions such as ddply) would be much appreciated. </p>