Skip to contents

This function computes the *interquartile range* of the x values. See the **Details** section below for further information.

Usage

iqr(x, i = NULL, na.rm = TRUE)

Arguments

x

(named) numerical vector

i

(optional) numerical vector giving the position in x or character vector matching the names in x. If missing or i = NULL, the entire x is considered for the computation of the score

na.rm

logical, whether to remove NA values from x before computation

Value

A numerical value representing the computed measure. A default NA value is returned if the score can't be computed.

Details

The *interquartile range* (also called *midspread* or *H-spread*) is a measure of statistical dispersion. It is defined as the difference between the 75th and 25th percentiles of the data:

$$IQR(x) = Q_{3}(x) - Q_{1}(x)$$

Since missing values and NaN's are allowed only if na.rm = TRUE in quantile, if x has NA values and na.rm = FALSE then NA is returned.

References

https://en.wikipedia.org/wiki/Interquartile_range

Author

Alessandro Barberis

Examples

x = c(7,7,31,31,47,75,87,115,116,119,119,155,177,NA)
iqr(x = x)#88
#> [1] 88