Skip to content
Back to formatted view

Raw Message

Message-ID: <42F392A8.2040900@stats.uwo.ca>
Date: 2005-08-05T16:24:08Z
From: Duncan Murdoch
Subject: Computing sums of the columns of an array
In-Reply-To: <42F390E9.3010301@metahuman.org>

On 8/5/2005 12:16 PM, Martin C. Martin wrote:
> 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?

You'd probably do better with matrix multiplication:

rep(1, nrow(A)) %*% A

Duncan Murdoch