You're missing a ^2
. This is your same code with the right formula.
x <- c(1, 6, 2, 7)
n <- length(x)
xBar <- mean(x)
...
StDev <- sqrt(sum((x - xBar)^2) / (n - 1))
And here you can see it gives the same output as sd()
.
StDev
[1] 2.94392
sd(x)
[1] 2.94392
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…