what is the R code to calculated a mean and standard deviation of multiple mean and standard deviations?

50 Views Asked by At

what is the R code to calculated a mean and standard deviation of multiple mean and standard deviations? each has its own number of items...

I tried to search online and in this forum but there was no straight answer...thank you!

2

There are 2 best solutions below

1
grapestory On

Would you be able to provide us with an example?

The R code to calculate a mean is

mean()

So for example if you had a set of numbers

values <- c(0, 4, 23, 4, 5)
mean(values)
[1] 7.2

You could nest mean() if you'd like

values <- c(mean(c(0, 15, 10)), mean(c(100, 4)))
mean(values)
[1] 30.16667
0
shghm On

If you have several means (lets call them a and b) and their corresponding standard deviations (lets call them saand sb) and you calculated the mean of means (via mean(c(a,b))) then you need to do "error propagation" for the corresponding standard deviation. In this case the new standard deviation sab would be: sab=1/2*sqrt(sa^2+sb^2)