title: How to do calculations in R with multiple data.frames or arrays?
body: <p>UPDATED - I need to perform calculations using 100+ 2-dimensional tables. I understand the tables can be imported into R as data.frames or arrays.</p>
  
  <p>Here is an example that illustrates my problem. For simplification, my many tables are represented by d1, d2, dd2 and dd3. Note that I added more data.frames into the list because the solution that @BondedDust proposed, that was replacing 'sum' by '+' worked when the list had 2 data.frames in it, but not the 4 data.frames.</p>
  
  <pre><code>d1 = mtcars
  d2 = d1*2
  dd2 = d2 * 2
  dd3 = d2 * d2
  </code></pre>
  
  <p>Below, d3 would be my desired final output if the operation were the '+'. But I need a way to automate this process.</p>
  
  <pre><code>d3 = d1+d2 + dd2 + dd3 
  &gt; str(d3)
  'data.frame':   32 obs. of  11 variables:
   $ mpg : num  2793 2793 3279 2898 2229 ...
   $ cyl : num  258 258 124 258 440 258 440 124 124 258 ...
   $ disp: num  154720 154720 70740 401190 780120 ...
   $ hp  : num  73370 73370 52545 73370 184975 ...
   $ drat: num  118.6 118.6 115.9 78.5 81.6 ...
   $ wt  : num  59.5 69.7 48.5 84.5 95.1 ...
   $ qsec: num  1741 1857 2208 2404 1857 ...
   $ vs  : num  0 0 13 13 0 13 0 13 13 13 ...
   $ am  : num  13 13 13 0 0 0 0 0 0 0 ...
   $ gear: num  124 124 124 75 75 75 75 124 124 124 ...
   $ carb: num  124 124 13 13 38 13 124 38 38 124 ...
  </code></pre>
  
  <p>So I tried with lists, but when I use do.call with '+' with the 4 data.frames in the list it doesn't work.</p>
  
  <pre><code>l1 = list(d1,d2,dd2,dd3)
  str(l1)
  
  &gt; str(l1)
  List of 4
   $ :'data.frame':   32 obs. of  11 variables:
    ..$ mpg : num [1:32] 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
  
  d4 = do.call('+', l1)
  Error in `+`(list(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4,  : 
    unused arguments (list(mpg = c(84, 84, 91.2, 85.6, 74.8, 72.4, 57.2, 97.6, 91.2, 76.8, 71.2, 65.6, 69.2, 60.8, 41.6, 41.6, 58.8, 129.6, 121.6, 135.6, 86, 62, 60.8, 53.2, 76.8, 109.2, 104, 121.6, 63.2, 78.8, 60, 85.6), cyl = c(24
  </code></pre>
  
  <p>This post <a href="https://stackoverflow.com/questions/9900690/r-vector-array-addition">R - Vector/ Array Addition</a> shows a similar problem, but they used arrays instead of data.frames. So, I tried converting the data.frames to arrays using this:</p>
  
  <pre><code>d5 = lapply(l1, function(x) data.matrix(x))
  </code></pre>
  
  <p>But d5 doesn't have the correct structure to do for example:</p>
  
  <pre><code>d6 = apply(d5,1:2,sum)
  </code></pre>
  
  <p>So, I'm not sure if the problem is in the way I'm using the lapply, the do.call or what. Any help or direction will be appreciated. Sorry if I missed a previous post that already addressed this issue, I've been searching the web all day and tried many different options and couldn't get a desirable outcome.
  Thanks!</p>