title: Sum elements of a list in R
body: <p>I have multiple files with the same structure. I would like to calculate the sum of each first element of each file. 
  Here is the head of one file: </p>
  
  <pre><code>&gt; head(NodesA1to10)
    NodeAMean NodeBMean NodeCMean NodeBMeanclo NodeCMeanclo NodeAMeanclo NodeBMeanin NodeCMeanin
  1       0.6       0.5       0.1   0.06978355   0.08988359   0.06957624   0.3890288   0.2389382
  2       0.6       1.1       0.4   0.04403793   0.04955660   0.04052408   0.4039787   0.2533702
  3       0.5       1.6       0.4   0.03244537   0.03386485   0.02925561   0.4301655   0.2714006
  4       0.6       2.7       1.3   0.02629242   0.02545891   0.02101667   0.4710782   0.2987464
  5       1.0       2.9       1.4   0.02194354   0.02050273   0.01643439   0.5221127   0.3531018
  6       1.8       5.1       2.0   0.01895985   0.01674231   0.01369418   0.5651066   0.3922610
    NodeAMeanin NodeBMeanout NodeCMeanout NodeAMeanout
  1   0.3550979    0.3236412    0.3807460    0.2786777
  2   0.6173852    0.4587713    0.4784292    0.4671891
  3   0.7020968    0.5933347    0.5594147    0.5536033
  4   0.7686962    0.7336590    0.6230537    0.5872133
  5   0.8024617    0.8738159    0.7147912    0.6457293
  6   0.8289504    1.0158102    0.7665834    0.7186818
  </code></pre>
  
  <p>I have in total 10 files with the same format. I would like to calculate sum in as below: </p>
  
  <pre><code>N&lt;-10
      B1_1 &lt;-sum(NodesA1to10$NodeBMean[1],NodesA11to20$NodeBMean[1],NodesA21to30$NodeBMean[1],NodesA31to40$NodeBMean[1],
                 NodesA41to50$NodeBMean[1],NodesA61to70$NodeBMean[1],NodesA71to80$NodeBMean[1],NodesA81to90$NodeBMean[1],
                 NodesA91to100$NodeBMean[1])/N
  
      B1_2 &lt;-sum(NodesA1to10$NodeBMean[2],NodesA11to20$NodeBMean[2],NodesA21to30$NodeBMean[2],NodesA31to40$NodeBMean[2],
                 NodesA41to50$NodeBMean[2],NodesA61to70$NodeBMean[2],NodesA71to80$NodeBMean[2],NodesA81to90$NodeBMean[2],
                 NodesA91to100$NodeBMean[2])/N
  </code></pre>
  
  <p>This code works for me, but I have to repeat it 10 times and further do it for different conditions, therefore I would really like to do it in faster way. I tried to use list: </p>
  
  <pre><code>allNodesA &lt;- list(NodesA1to10,NodesA11to20,NodesA21to30,
                    NodesA31to40,NodesA41to50,NodesA51to60,NodesA61to70,
                    NodesA71to80,NodesA81to90,NodesA91to100)
  B1&lt;-lapply(allNodesA, function(z) { z$NodeBMean &lt;- sum(z$NodeBMean[[1]]);z})
  NodesBb&lt;-do.call(rbind.data.frame, B1)
  B1&lt;-list()
  for (j in 1:10)
  {
    B1[[j]]&lt;-lapply(allNodesA, function(z) { sum(z[[j]]$NodeBMean[j])})
  }
  </code></pre>
  
  <p>But this solution gives me an error: </p>
  
  <pre><code> Error in z[[j]]$NodeBMean : $ operator is invalid for atomic vectors
  </code></pre>
  
  <p>Could someone please help me how to find more optimal ways to get a sum of every 1st, 2nd....10th element from many files? </p>