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

gmd(x, ...)

Arguments

x

A vector or data frame.

...

Optional, unquoted names of variables 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. You may also use functions like : or tidyselect's select_helpers.

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, e17age, c160age, c12hour)
#> # A tibble: 1 x 3 #> e17age c160age c12hour #> <dbl> <dbl> <dbl> #> 1 9.30 15.2 47.9
gmd(efc, tidyselect::contains("cop"))
#> # A tibble: 1 x 9 #> c82cop1 c83cop2 c84cop3 c85cop4 c86cop5 c87cop6 c88cop7 c89cop8 c90cop9 #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 0.562 0.715 0.852 0.886 0.592 0.484 0.959 1.14 1.04