Skip to content
Prev 75059 / 398502 Next

Computing sums of the columns of an array

Duncan Murdoch wrote:

            
No, better use colSums(), which has been optimized for this purpose:

  A <- matrix(seq(1, 10000000), ncol=10000)
  system.time(colSums(A))
  # ~ 0.1 sec.
  system.time(rep(1, nrow(A)) %*% A)
  # ~ 0.5 sec.


Uwe Ligges