Skip to content
Prev 33361 / 398502 Next

more efficient sum of matrix columns

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
   i<-i+1
}
#data is the original 4462*202 matrix.

thanks,
On Sat, 14 Jun 2003, John Fox wrote: