Re: [R] colSums

About this list Date view Thread view Subject view Author view Attachment view

From: Marcel Wolbers (wolbers@stat.math.ethz.ch)
Date: Thu 19 Jul 2001 - 16:35:41 EST


Message-id: <15190.32701.295873.994634@gargle.gargle.HOWL>


>> 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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Wed 10 Mar 2004 - 08:18:20 EST