Learn R Programming

netcom (version 2.1.6)

gini: Gini coefficient

Description

Takes a matrix and returns the Gini coefficient of each column.

Usage

gini(input, byrow = FALSE)

Value

A vector of the Gini coefficients of each column.

Arguments

input

A matrix where the Gini coefficient will be calculated on each column. Note that vector data must be converted to a single-column matrix.

byrow

Defaults to FALSE. Set to TRUE to calculate the Gini coefficient of each row.

References

Gini, C. (1912). Variabilita e mutabilita. Reprinted in Memorie di metodologica statistica (Ed. Pizetti E, Salvemini, T). Rome: Libreria Eredi Virgilio Veschi.

Examples

Run this code
# Vectors are not supported. First convert to a single-column matrix.
sample_data <- runif(20, 0, 1)
gini(matrix(sample_data, ncol = 1))

# Multiple Gini coefficients can be calculated simultaneously
gini(matrix(sample_data, ncol = 2)) 

Run the code above in your browser using DataLab