Re: [R] more efficient sum of matrix columns

2003-06-15 Thread Jean Eid
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

Re: [R] more efficient sum of matrix columns

2003-06-15 Thread Jonck van der Kogel
PROTECTED] Subject: [R] more efficient sum of matrix columns 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 lo

Re: [R] more efficient sum of matrix columns

2003-06-15 Thread Roger D. Peng
colSums()/rowSums() will be *much* faster and you can specify na.rm = TRUE. -roger Jonathan Baron wrote: 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 bui

Re: [R] more efficient sum of matrix columns

2003-06-14 Thread John Fox
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 faster

Re: [R] more efficient sum of matrix columns

2003-06-14 Thread Jonathan Baron
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

[R] more efficient sum of matrix columns

2003-06-14 Thread Jean Eid
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 * 20