title: How to sum two matrices by seq_along in r?
body: <p>I have two matrices that i want to sum</p>
  
  <pre><code>mat1&lt;-matrix(1:4,2,2)    
  mat2&lt;-matrix(5:8,2,2)
  mat1
       [,1] [,2]
  [1,]    1    3
  [2,]    2    4
  
  mat2
   [,1] [,2]
  [1,]    5    7
  [2,]    6    8
  </code></pre>
  
  <p>what i want is this</p>
  
  <pre><code>mat_sum
       [,1] [,2]
  [1,]    6   10
  [2,]    8   12 
  </code></pre>
  
  <p>I tried </p>
  
  <pre><code>mat_sum &lt;- sapply(seq_along(mat1), function(i)
  mat1[[i]]+mat2[[i]])
  </code></pre>
  
  <p>but then it doesnt return a matrix</p>
  
  <pre><code>[1]  6  8 10 12
  </code></pre>
  
  <p>How can i get it to return a matrix?</p>