0 0
As you can see this took so little time it actually came out as 0. And
my system is not fast at all (powermac 9600 with a G4 700 MHz upgrade).
HTH, Jonck
From: Jean Eid [EMAIL PROTECTED]
Date: zon jun 15, 2003 02:51:29 Europe/Amsterdam
To: [EMAIL PROTECTED]
Subject: [R] more efficient sum
this is what my program read
dataa-data.frame(matrix(0, nrow=nrow(data), ncol=ncol(data))
i-1
j-1
while(i=nrow(data))
{
if(data$Index.Price==1)
data1[j,]-data[i,]
else
{
num-data$No.Primary[i]
data[j,]-apply(data[i:i+num-1,],2,sum)
i-i+num-1
}
j-j+1
Dear R users,
I am looking for a more efficient way to compute the sum of columns of a
matrix.
I am currently using apply(data, 2, sum) however, I am building a data set
from another one by summing the columns of some parts of the matrix.
the loop is taking too long (about 1/2 hour) for a 4462 *
On 06/14/03 20:51, Jean Eid wrote:
Dear R users,
I am looking for a more efficient way to compute the sum of columns of a
matrix.
I am currently using apply(data, 2, sum) however, I am building a data set
from another one by summing the columns of some parts of the matrix.
the loop is taking too
Dear Jean and Jonathan,
colSums() should be more efficient, but (unless I misunderstand the size of
the problem) a problem this small shouldn't take a half hour. On my ageing
800 MHz, 512MB Windows 2000 PC, the result was essentially instantaneous
either way, though an order of magnitude