title: Calculate rowSums for three-dimensional array without for-loop/apply
body: <p>Take array <code>b_array</code>:</p>
  
  <pre><code>set.seed(123)
  a_mtx = matrix(1:15,ncol=5)
  b_mtx = matrix(seq(1,5,length.out=30),ncol=5)
  
  b_array = 
    array(
      b_mtx,
      dim = 
        c(
          nrow(b_mtx),
          ncol(b_mtx), 
          nrow(a_mtx)
        )
      )
  </code></pre>
  
  <p>If I want to calculate the sum of each column of each "slice" or "sheet" of <code>b_array</code>, I can use <code>colSums</code> with its dimension argument:</p>
  
  <pre><code>colSums(b_array, dim = 1)
  #          [,1]      [,2]      [,3]
  #[1,]  8.068966  8.068966  8.068966
  #[2,] 13.034483 13.034483 13.034483
  #[3,] 18.000000 18.000000 18.000000
  #[4,] 22.965517 22.965517 22.965517
  #[5,] 27.931034 27.931034 27.931034
  </code></pre>
  
  <p>To do the same for row sums, I cannot use <code>rowSums</code>'s dimension argument, as it is treated differently, so I resort to an <code>apply</code>:</p>
  
  <pre><code>apply(b_array, 3, rowSums)
  #         [,1]     [,2]     [,3]
  #[1,] 13.27586 13.27586 13.27586
  #[2,] 13.96552 13.96552 13.96552
  #[3,] 14.65517 14.65517 14.65517
  #[4,] 15.34483 15.34483 15.34483
  #[5,] 16.03448 16.03448 16.03448
  #[6,] 16.72414 16.72414 16.72414
  </code></pre>
  
  <p>I wish to perform the same calculation on an array with much larger dimension, so that <code>apply</code> and other for-loop methods are not efficient.</p>
  
  <p>Are there any alternative, truly vectorized methods?</p>