[R] var on a vector

Philippe Glaziou glaziou at pasteur-kh.org
Thu Oct 2 13:44:04 CEST 2003


landau at poleia.lip6.fr <landau at poleia.lip6.fr> wrote:
> I am an "R" newbie. I have a problem with computing a variance
> on a vector.
> 
> > data(cars) variance <- function (x) mean(x^2)-mean(x)^2;
> > variance(cars[,1])
> [1] 27.4
> > var(cars[,1])
> [1] 27.95918
> 
> What did I assume/understand wrong ?


You wrongly assumed that the 'var' help file would not help.
However, that page states that the denominator n-1 is used.

> 27.4*50/49
[1] 27.95918

-- 
Philippe




More information about the R-help mailing list