[R] Means
(Ted Harding)
ted.harding at wlandres.net
Fri Feb 18 23:12:04 CET 2011
On 18-Feb-11 20:51:40, Dmitry Berman wrote:
> Listers,
>
> Is there a command/function to get the population standard deviation
> (N) and
> the sample standard deviation (n-1)
>
> Thanks
Using data (1:10), with N=10, as an example:
c(SampSD=1, PopSD=sqrt(9/10))*sd((1:10))
# SampSD PopSD
# 3.027650 2.872281
More generally, with data x and N<-length(x):
c(SampSD=1, PopSD=sqrt((N-1)/N))*sd(x)
These are examples of commands. You could wrap the latter into
a function on the lines of:
PopSampSD <- function(x){
N <- length(x)
c(SampSD=1, PopSD=sqrt((N-1)/N))*sd(x)
}
and then:
PopSampSD((1:10))
# SampSD PopSD
# 3.027650 2.872281
as before. Hoping this helps,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 18-Feb-11 Time: 22:12:00
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list