R/competitiveness.R

Defines functions competitiveness

Documented in competitiveness

#  Party System Indicators - Competitiveness----

competitiveness <- function(votes) {
     if (class(votes) != 'numeric') {
          stop('Input vector must be numeric')
     }
     if (length(votes) < 2 & class(votes) == 'numeric') {
          stop('Input vector must have minimal lenght of 2.')
     }
     fractions <- sort(votes/sum(votes), decreasing = TRUE)
     1 - (fractions[1] - fractions[2])
}
albuja/electoral documentation built on Feb. 7, 2023, 5:12 a.m.