Learn R Programming

psych (version 1.0-77)

SD: Find the Standard deviation for a vector, matrix, or data.frame - do not return error if there are no cases

Description

Find the standard deviation of a vector, matrix, or data.frame. In the latter two cases, return the sd of each column. Unlike the sd function, return NA if there are no observations rather than throw an error.

Usage

SD(x, na.rm = TRUE)

Arguments

x
a vector, data.frame, or matrix
na.rm
na.rm is assumed to be TRUE

Value

  • The standard deviation

Details

Finds the standard deviation of a vector, matrix, or data.frame. Returns NA if no cases.

Just an adaptation of the stats:sd function to return the functionality found in R < 2.7.0 or R >= 2.8.0

See Also

These functions use SD rather than sd: describe.by, skew, kurtosi

Examples

Run this code
data(attitude)
sd(attitude) #all complete
attitude[,1] <- NA
SD(attitude) #missing a column
describe(attitude)

Run the code above in your browser using DataLab