Skip to content

Instantly share code, notes, and snippets.

View turbanisch's full-sized avatar

Felix Turbanisch turbanisch

  • University of Göttingen
  • Göttingen
View GitHub Profile
@turbanisch
turbanisch / herfindahl
Created August 18, 2022 11:58
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)
}