title: R Average over a list of data frames
body: <p>If I have a list of data frames in R, such as:</p>
  
  <pre><code>x&lt;-c(1:10)
  y&lt;-2*x
  z&lt;-3*x
  df.list &lt;- list(data.frame(x),data.frame(y),data.frame(z))
  </code></pre>
  
  <p>And I'd like to average over a specific column (this is a simplified example) of all these data frames, is there any easy way to do it?</p>
  
  <p>The length of the list is known but dynamic (i.e. it can change depending on run conditions).</p>
  
  <p>For example:</p>
  
  <pre><code>dfone&lt;-data.frame(c(1:10))
  dftwo&lt;-data.frame(c(11:20))
  dfthree&lt;-data.frame(c(21:30))
  </code></pre>
  
  <p>(Assume all the column names are <code>val</code>)</p>
  
  <pre><code>row, output
  1,    (1+11+21)/3 = 11
  2,    (2+12+22)/3 = 12
  3,    (3+13+23)/3 = 13
  </code></pre>
  
  <p>etc</p>
  
  <p>So <code>output[i,1] = (dfone[i,1]+dftwo[i,1]+dfthree[i,1])/3</code></p>
  
  <p>To do this in a for loop would be trivial:</p>
  
  <pre><code>for (i in 1:length(dfone))
  {
    dfoutput[i,'value']=(dfone[i,'value']+dftwo[i,'value']+dfthree[i,'value'])/3
  }
  </code></pre>
  
  <p>But I'm sure there must be a more elegant way?</p>