Skip to content
Prev 17971 / 398502 Next

compute variance of every column in a matrix without a loop

On Sat, 16 Mar 2002, Francisco J Molina wrote:

            
No, but you can make it look as if there's no loop.

You can hide the for() loop inside a function with
  apply(m, 2, var)
if the reason you want to avoid a loop is to make your code look simpler.

In 1.5.0 you will be able to do
   colMeans(m*m)-colMeans(m)^2
if the reason is to have the loop take place in compiled code and be
faster.


	-thomas


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._