Calculates number of seats for the respective parties according to the method of d'Hondt.

dHondt(votes, parties, n_seats = 183)

Arguments

votes

Number of votes per party.

parties

Names of parties (must be same length as votes).

n_seats

Number of seats in parliament. Defaults to 183 (seats in Austrian parliament).

Value

A named integer vector of seat counts, one entry per party, in the same order as parties. The vector has a logical attribute ties: TRUE if two or more parties had equal claim to the last seat (i.e. the result is not uniquely determined and was resolved randomly), FALSE otherwise. When ties = TRUE, re-running with a different random seed may produce a different but equally valid seat distribution.

See also

Examples

library(coalitions)
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
# get the latest survey for a sample of German federal election polls
surveys <- get_latest(surveys_sample) %>% ungroup() %>% slice(1) %>% tidyr::unnest("survey")
# calculate the seat distribution based on D'Hondt for a parliament with 300 seats
dHondt(surveys$votes, surveys$party, n_seats = 300)
#> [1]  24 114  24  24  27  15  72
#> attr(,"ties")
#> [1] TRUE