Simple example for mean, variance and sd - but getting different results in R

730 views Asked by At

Trying to use R/Rstudio (latest version), to calculate the: - Mean, - Variance and - Std Deviation in this specific, simple problem:

http://www.mathsisfun.com/data/standard-deviation.html

...but my R results are different from the example page, above.

This is what I did in R:

>  dogs 
[1] 600 470 170 430 300
>  str(dogs) 
 num [1:5] 600 470 170 430 300
>  mean(dogs) 
[1] 394      ## page result: mean = 394, ok!
>  var(dogs) 
[1] 27130    ## page result:  var = 21,704 ?
>  sd(dogs) 
[1] 164.7119 ## page result:   sd = 147 ?
> 

Q1: Am I using the wrong R functions? Q2: Are there any other R functions/packages which would yield the correct answer, easily and directly? (the "summary" and the "summarize" function in dplyr pkg. don't give these results either...).

Thanks for any pointers...

UPDATE:----------------- I finally figured it out: - R uses the SAMPLE var and sd functions - the example page uses the POPULATION var and sd functions (which are not "natively" available in R).

Thus the difference in results...

Which leaves me hanging w/these 2 relevant Questions:

Q1 - Why are the POPULATION sd() and var() functions not "natively" available in R? (instead of having each user define the functions manually) and

Q2 - Is there an R-package in CRAN which includes a super-set of Descriptive Statistics functions, not "natively" available in R?

Thanks for any pointers, ideas etc...

0

There are 0 answers