View source: R/specific_calculations.R
instant_runoff_voting | R Documentation |
This is a recursive function and may take some time to run.
instant_runoff_voting(df)
df |
(Dataframe) A dataframe that must contain these three columns:
The dataframe should be in long format: each For an example, see the |
It calculates the results of an instant run-off voting election where each voter assigns a rank preference to a candidate (1 == most preferred, 2 == second-most, etc.). Everyone's first-preferences are counted, and if no candidate gets >50% of the first-preferences, the candidate who got the fewest preferences is removed, the people who voted for them have their votes passed down to their next-preferred candidate, and the process begins again.
A dataframe showing the winners and the proportion of votes they got.
Desi Quintans (http://www.desiquintans.com)
head(nz_boty_2019_head)
#> # A tibble: 6 × 3
#> voter rank candidate
#> <int> <int> <chr>
#> 1 1 1 Gibson's Albatross
#> 2 1 2 Tūī
#> 3 1 3 Kākā
#> 4 1 4 Kākāpō
#> 5 1 5 Little Spotted Kiwi
#> 6 2 1 Spotted Shag
instant_runoff_voting(nz_boty_2019_head)
#> candidate prop
#> Yellow-eyed penguin 0.5009901
#> Kākāpō 0.4990099
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.