standard deviation sd var

hello, i need some help.
How to write one line code that will calculate the standard deviation in the sample, without using the var or sd functions? A vector of x, non-zero length, contains the sample numeric values.
Thanks a lot.

For x having length > 1 and not having any missing, we can use the following

x<-mtcars$mpg
x
#>  [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
#> [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
#> [31] 15.0 21.4
# sample sd for x
sqrt(sum((x-mean(x))**2)/(length(x)-1))
#> [1] 6.026948
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.