# sd

##### Standard Deviation

This function computes the standard deviation of the values in
`x`

.
If `na.rm`

is `TRUE`

then missing values are removed before
computation proceeds.

- Keywords
- univar

##### Usage

`sd(x, na.rm = FALSE)`

##### Arguments

- x
- a numeric vector or an R object which is coercible to one
by
`as.vector(x, "numeric")`

. - na.rm
- logical. Should missing values be removed?

##### Details

Like `var`

this uses denominator $n - 1$.

The standard deviation of a zero-length vector (after removal of
`NA`

s if `na.rm = TRUE`

) is not defined and gives an error.
The standard deviation of a length-one vector is `NA`

.

##### See Also

##### Examples

`library(stats)`

```
sd(1:2) ^ 2
```

*Documentation reproduced from package stats, version 3.2.2, License: Part of R 3.2.2*

### Community examples

**richie@datacamp.com**at Jan 17, 2017 stats v3.3.1

The standard deviation of random numbers should be close to (but not exactly) what you ask for. ```{r} x <- rnorm(1000, sd = 5) sd(x) ``` If there are any missing values, the standard deviation is also missing. ```{r} sd(c(1, 2, NA)) ``` You can exclude missing values by setting `na.rm = TRUE`. ```{r} sd(c(1, 2, NA), na.rm = TRUE) ``` If `x` has length 1 or 0, the result is `NA`. ```{r} sd(1) sd(numeric()) ```