Please use colMeans()! was: Re: [R] Calculate Mean of Column Vectors?

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Jan 11 08:56:55 CET 2005


Folks, please see ?colMeans (as already pointed out in at least one 
message) and friends.
These are faster than those apply(X, 2, mean) calls
and please do use them when publishing code (both in packages in on this 
list).

Uwe Ligges


>>Hello,
>>
>>I've got an array defined as y <- rnorm(3000), dim(y) <- c(3, 1000).
>>
>>I'd like to produce a 1000-element vector z that is the mean of the 
>>corresponding elements of y (like z[1,1] <- mean(y[1,1], y[2,1], 
>>y[3,1])), but being new to R, I'm not sure how to do this for all 
>>elements at once (or, at least, simply). Any help is appreciated.
>>
>>Thanks,
>>
>>Tom




More information about the R-help mailing list