Skip to contents

This function computes the standard deviation (SD) of the values in x.

See the Details section below for further information.

Usage

sd(x, g = NULL, na.rm = TRUE)

Arguments

x

numerical vector.

g

(optional) vector or factor object giving the group for the corresponding elements of x.

na.rm

logical indicating whether missing values should be removed before computation.

Details

This function is a wrapper to the sd function.

If x can be partitioned into \(c\) subgroups (provided by g), then the \(SD\) is computed for each class.

Examples

#Seed
set.seed(1010)

#Define size
n = 10

#Data
x = sample.int(n = 100, size = n, replace = TRUE)

#Grouping variable
g = c(rep("a", n/2), rep("b", n/2))

#Standard deviation
sd(x)
#> [1] 28.49737

#Standard deviation by group
sd(x = x, g = g)
#>        a        b 
#> 34.60058 14.62874