title: How to add two columns from each matrix in a list of matrices in R?
body: <p>I have a list of matrices and I want to combine two columns by calculating the mean and, finally, remove one of them. I know how I could do it with just one matrix but not with many matrices in a list.</p>
  
  <p>Let’s say we have a matrix with 3 columns. This is what I want to do:</p>
  
  <pre><code>matrix &lt;- matrix(1:9,ncol=3)
  matrix[,2] &lt;- (matrix[,2] + matrix[,3]) / 2
  matrix &lt;- matrix[,-3]
  </code></pre>
  
  <p>The removal of the column can be done like this:</p>
  
  <pre><code>list &lt;- lapply(list, function(x)x[,-3])
  </code></pre>
  
  <p>But how can I achieve the first part with a list of matrices?</p>
  
  <pre><code>list &lt;- list(matrix(1:9, ncol=3), matrix(3:11, ncol=3))
  </code></pre>