gmd() computes Gini's mean difference for a numeric vector or for all numeric vectors in a data frame.

gmd(x, select = NULL)

Arguments

x

A vector or data frame.

select

Optional, names of variables as character vector that should be selected for further processing. Required, if x is a data frame (and no vector) and only selected variables from x should be processed.

Value

For numeric vectors, Gini's mean difference. For non-numeric vectors or vectors of length < 2, returns NA.

Note

Gini's mean difference is defined as the mean absolute difference between any two distinct elements of a vector. Missing values from x are silently removed.

References

David HA. Gini's mean difference rediscovered. Biometrika 1968(55): 573-575

Examples

data(efc)
gmd(efc$e17age)
#> [1] 9.297005
gmd(efc, c("e17age", "c160age", "c12hour"))
#>   variable       gmd
#> 1   e17age  9.297005
#> 2  c160age 15.185966
#> 3  c12hour 47.874877