Skip to contents

Calculate standard deviation of x, where x can be an rvec. If x is an rvec, separate standard deviations are calculated for each draw.

Usage

sd(x, na.rm = FALSE)

Arguments

x

A numeric vector or R object, including an rvec().

na.rm

Whether to remove NAs before calculating standard deviations.

Value

An rvec, if x is an rvec. Otherwise typically a numeric vector.

Details

To enable different behavior for rvecs and for ordinary vectors, the base R function stats::sd() is turned into a generic, with stats::sd() as the default.

For details on the calculations, see the documentation for stats::sd().

See also

Examples

x <- rvec(cbind(rnorm(10), rnorm(10, sd = 20)))
x
#> <rvec_dbl<2>[10]>
#>  [1] 0.5422,-26.09 0.7411,5.517  0.7644,15.72  0.8188,-9.72  -1.183,30.29 
#>  [6] -1.864,4.549  0.4572,-10.35 -2.135,-7.376 -1.22,-53.25  -2.154,-20.27
sd(x)
#> <rvec_dbl<2>[1]>
#> [1] 1.297,23.32