[R] population variance and sample variance

Peng Yu pengyu.ut at gmail.com
Mon Oct 19 17:30:57 CEST 2009

It seems that var() computes sample variance. It is straight forward
to compute population variance from sample variance. However, I feel
that it is still convenient to have a function that can compute
population variance. Is there a population variance function available
in R?

$ Rscript var.R
> set.seed(0)
> n = 4
> x = rnorm(n)
> var(x)
[1] 0.6526278
> sum((x-mean(x))^2)/(n-1)
[1] 0.6526278

More information about the R-help mailing list