title: array output from apply() in R
body: <p>Suppose I have:</p>
  
  <pre><code>aa &lt;- seq(2,10, length=3)
  bb &lt;- seq(20,30, length=2)
  cc &lt;- seq(10,11, length=2)
  
  fun &lt;- function(a,b,c) {return(a+b-c)}
  
  out &lt;- array(dim=c(length(aa), length(bb), length(cc)))
  for(i in 1:length(aa)) {
    for(j in 1:length(bb)) {
      for(k in 1:length(cc)) {
        out[i,j,k] &lt;- fun(aa[i], bb[j], cc[k])
      }
    }
  }
  </code></pre>
  
  <p>Aiming for a faster alternative, I then tried apply() as follows</p>
  
  <pre><code>b2 &lt;- rep(bb, each=2)
  abc &lt;- rbind(rep(aa, each=2*2), rep(bb, each=2), rep(cc,6))
  out2 &lt;- apply(abc, 2, function(x){ fun(x[1], x[2], x[3]) } )
  </code></pre>
  
  <p>This basically does the same calculation as before but I couldn't get the format of "out2" to be in the array as "out". Can you correct the below code so that out and out2 are exactly the same? Thanks so much in advance</p>
  
  <pre><code>out2 &lt;- array(out2, dim=dim(out))
  </code></pre>