Re: [R] Computing sums of the columns of an array

From: Huntsinger, Reid <reid_huntsinger_at_merck.com>
Date: Sat 06 Aug 2005 - 02:23:14 EST


colSums() is a lot faster.

Reid Huntsinger

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Martin C. Martin Sent: Friday, August 05, 2005 12:17 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Computing sums of the columns of an array

Hi,

I have a 5x731 array A, and I want to compute the sums of the columns. Currently I do:

apply(A, 2, sum)

But it turns out, this is slow: 70% of my CPU time is spent here, even though there are many complicated steps in my computation.

Is there a faster way?

Thanks,
Martin



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Aug 06 02:30:30 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:06:14 EST