[R] compute variance of every column in a matrix without a loop

Jonathan Baron baron at cattell.psych.upenn.edu
Sun Mar 17 12:57:30 CET 2002


On 03/16/02 19:43, Francisco J Molina wrote:
>Is it possible to compute the variance of every column in a matrix
>without a loop?

If the matrix is m1,

apply(m1,2,var)

or, with missing data,

apply(m1,2,var,na.rm=T)

In general, apply() and related functions are well worth
understanding.
-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list