[R] colSums

Marcel Wolbers wolbers at stat.math.ethz.ch
Thu Jul 19 08:35:41 CEST 2001


>> My question: Are there equivalents to colSums in R?
I don't think there are functions for doing this, but you can speed 
up things a lot by using matrix operations instead of apply if
this is possible:

> x <- matrix(rnorm(1E5),ncol=100)
> system.time(tmp1 <- apply(x,2,sum))
[1] 0.04 0.01 0.05 0.00 0.00
> system.time(tmp2 <- c(rep(1,nrow(x))%*%x))
[1] 0.01 0.00 0.01 0.00 0.00
> all.equal(tmp1,tmp2)
[1] TRUE

Yours,
Marcel Wolbers

-- 
Marcel Wolbers, LEO C14, Seminar for Statistics, ETH Zurich
CH-8092 Zurich, Switzerland; phone: (01) 632 2252	
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list