Reputation: 13
I want to know the standard deviation of every column i have in a data frame. Right now i'm using the formula
apply(df,2,sd)
But it's showing me the sample standard deviation, what is the way to find the population standard deviation in this scenario?
Upvotes: 0
Views: 338
Reputation: 66480
We can define the calculation for population standard deviation:
sd.p=function(x){sd(x)*sqrt((length(x)-1)/length(x))}
# From https://stackoverflow.com/a/66349386/6851825
And then use your formulation:
apply(mtcars,2,sd.p)
mpg cyl disp hp drat wt qsec vs
5.9320296 1.7577951 121.9867814 67.4830708 0.5262581 0.9630477 1.7588006 0.4960784
am gear carb
0.4911323 0.7261844 1.5897622
From other answers in that question it looks like there is not a built-in function for this in base R, but a number of packages include a function to that effect: https://stackoverflow.com/a/59120744/6851825
Upvotes: 2