Skip to contents

This is a rewrite of OasisR::HLoc, an implementation of the Shannon-Weiner entropy-based diversity index. It takes a data frame of population counts (not shares!), where each row is one location and each column is a mutually exclusive demographic group. It then returns the index for each location.

Usage

diversity(x)

Arguments

x

A data frame containing only numeric columns, where each column represents counts of population groups

Value

A numeric vector of index values, with length the same as the number of rows in x

See also

OasisR::HLoc now defunct

Examples

  race <- data.frame(white = c(3394, 3036, 1527),
                     black = c(13, 779, 448),
                     latino = c(38, 99, 125),
                     asian = c(0, 18, 34),
                     other_race = c(29, 120, 170))
 diversity(race)
#> [1] 0.08264657 0.46741890 0.62362627