Learn R Programming

softwareRisk (version 0.1.0)

gini_index_fun: Compute the Gini index of a numeric vector

Description

Computes the Gini index (a measure of inequality) for a numeric vector. Non-finite (NA, NaN, Inf) values are removed prior to computation. If fewer than two finite values remain, the function returns 0.

Usage

gini_index_fun(x)

Value

A numeric scalar giving the Gini index of x.

Arguments

x

Numeric vector.

Details

The Gini index ranges from 0 (perfect equality) to 1 (maximal inequality).

Examples

Run this code
gini_index_fun(c(1, 1, 1, 1))
gini_index_fun(c(1, 2, 3, 4))
gini_index_fun(c(NA, 1, 2, Inf, 3))

Run the code above in your browser using DataLab