View source: R/input_wrapper.R
| dop_irv | R Documentation |
Compute the preference in each round of instant runoff voting from input data, transforming the results into a tidy format for visualization. Each row represents one round, with columns for each candidate's preference percentage and the election winner.
dop_irv(x, value_type = c("percentage", "count"), ...)
x |
Input data. Accepts the same formats as
|
value_type |
Character string specifying the output format. Either:
|
... |
Additional arguments passed to
|
A tibble with the following structure:
round: Integer, the round number (1 to n)
One column per candidate: Numeric, the percentage of votes (0-1) that candidate received in that round. NA values are replaced with 0 for eliminated candidates.
winner: Character, the name of the eventual IRV winner (same for all rows)
# Example 1: From preference vector
votes <- prefio::preferences(c("A > B > C", "B > A > C", "C > B > A", "A > B > C"))
dop_irv(votes, value_type = "count")
# Example 2: From data frame with custom column names
vote_data <- tibble::tibble(
prefs = prefio::preferences(c("A > B > C", "B > C > A", "C > A > B")),
counts = c(100, 75, 25)
)
dop_irv(vote_data, value_type = "percentage",
preferences_col = prefs,
frequency_col = counts)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.