Learn R Programming

lsr (version 1.0.0)

aad: Mean absolute deviation

Description

Calculates the mean absolute deviation from the sample mean.

Usage

aad(x, na.rm = FALSE)

Value

A single number giving the mean absolute deviation.

Arguments

x

A numeric vector containing the observations.

na.rm

Set to TRUE to remove missing values before computing the deviation. Defaults to FALSE.

Details

Computes the average of the absolute differences between each observation and the sample mean of x, i.e. mean(abs(x - mean(x))).

See Also

Examples

Run this code
x <- c(1, 3, 6)
aad(x)

# missing values
x <- c(1, 3, NA, 6)
aad(x) # returns NA
aad(x, na.rm = TRUE) # ignores the missing value

Run the code above in your browser using DataLab