Skip to content

Instantly share code, notes, and snippets.

@turbanisch
Created August 18, 2022 11:58
Show Gist options
  • Save turbanisch/f126dfb7ac9b2d8bc49ef5a40f370da1 to your computer and use it in GitHub Desktop.
Save turbanisch/f126dfb7ac9b2d8bc49ef5a40f370da1 to your computer and use it in GitHub Desktop.
Herfindahl–Hirschman index
herfindahl <- function(x, shares_in_percent = FALSE, na.rm = FALSE) {
shares <- x / sum(x, na.rm = na.rm)
if (shares_in_percent) shares <- shares * 100
sum(shares^2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment