title: How to sum a result of the repeated function in R
body: <p>I have a very complicated function. I need to repeat this function several times and sum the result. This is easy. However, I need to sum them at the same time. Since my function is difficult to show it here, I provide a very simple example just to explain my idea. Please note that (based on the amazing questions from the comments) My function needs to be done pairwise. Also, my matrices are all the same dimensions. Finally, the result is not as a list. I need to assign the result to a new variable. That is,</p>
  
  <pre><code>Res &lt;– myfunc(x[i,j],y[i,j])+myfunc(z[i,j],t[i,j])+..+..
  </code></pre>
  
  <p>Also, my function must loop over the elements of the matrices. <code>x[i,j]</code>.</p>
  
  <p>My matrices are stored in a list. </p>
  
  <p><code>Mymatrices–list(x,y,z,t)</code>. </p>
  
  <p>For example, </p>
  
  <pre><code>x &lt;- matrix(5,5,5)
  x[upper.tri(x,diag=T)] &lt;- 0
  y &lt;– matrix(4,5,5)
  y[upper.tri(y,diag=T)] &lt;- 0
  z &lt;- matrix(3,5,5)
  z[upper.tri(z,diag=T)] &lt;- 0
  t &lt;- matrix(2,5,5)
  t[upper.tri(t,diag=T)] &lt;- 0
  
  myfunc &lt;– function(x,y){
  
  sum(x,y)
  
  }
  </code></pre>
  
  <p>I would like it like this:</p>
  
  <pre><code> Res &lt;– myfunc(x[i,j],y[i,j])+myfunc(z[i,j],t[i,j])+..+..
  </code></pre>
  
  <p>Suppose I have <code>10</code> matrices and would like to have the sum as shown above. It is hard to do it manually. I would like to do this automatically. <code>lapply</code> function takes a list and I do not want it as a list.</p>
  
  <p>Any help, please?</p>