sd {stats} | R Documentation

## Standard Deviation

### Description

This function computes the standard deviation of the values in `x`. If `na.rm` is `TRUE` then missing values are removed before computation proceeds.

### Usage

    sd(x, na.rm = FALSE)

### Arguments

`x` | a numeric vector or an R object which is coercible to one by `as.vector`. Earlier versions of R allowed matrices or data frames for `x`, see below.
`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`.

In earlier versions R, for a `data.frame dfrm`, `sd(dfrm)` worked directly. This is deprecated now, and you are expected to use `sapply(dfrm, sd)` instead.

### See Also

`var` for its square, and `mad`, the most robust alternative.

### Examples

    sd(1:2) ^ 2

[Package stats version 2.15.1 Index]