This function computes the median absolute deviation (MAD) of the values in
x
.
See the Details section below for further information.
Arguments
- x
numerical vector.
- g
(optional) vector or factor object giving the group for the corresponding elements of
x
.- na.rm
logical indicating whether missing values should be removed before computation.
Details
This function is a wrapper to the mad
function.
If x
can be partitioned into \(c\) subgroups (provided by g
),
then the \(MAD\) is computed for each class.
Examples
#Seed
set.seed(1010)
#Define size
n = 10
#Data
x = sample.int(n = 100, size = n, replace = TRUE)
#Grouping variable
g = c(rep("a", n/2), rep("b", n/2))
#Median Absolute Deviation
mad(x)
#> [1] 29.652
#Median Absolute Deviation by group
mad(x = x, g = g)
#> a b
#> 34.0998 16.3086