# 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 but not a

`factor`

coercible to numeric by`as.double(x)`

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

##### Details

Like `var`

this uses denominator \(n - 1\).

The standard deviation of a length-one or zero-length vector is `NA`

.

##### See Also

##### Examples

`library(stats)`

```
# NOT RUN {
sd(1:2) ^ 2
# }
```

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

### 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()) ```