more efficient sum of matrix columns
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 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 * 202 matrix.
colSums() might be faster, but I don't know how much faster. It does not allow na.rm=T, but you don't have that, so it might help. -- Jonathan Baron, Professor of Psychology, University of Pennsylvania R page: http://finzi.psych.upenn.edu/
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help