fct_relabel_election_parties | R Documentation |
Relabels a factor that contains election parties from/to the different FOKUS election party name types.
fct_relabel_election_parties(
fct,
from_type = c("qstnr", "run", "short"),
to_type = c("short", "run", "qstnr"),
ballot_date = pal::pkg_config_val("ballot_date"),
lvl = lvls(ballot_date, canton, ballot_type = "election", prcds = "proportional"),
canton = cantons(ballot_date),
election_nr = 1L,
past = FALSE,
strict = TRUE
)
fct |
Factor to be relabelled. |
from_type |
Name type to convert from. One of |
to_type |
Name type to convert to. One of |
ballot_date |
FOKUS-covered ballot date. One of
|
lvl |
Political level. One of |
canton |
FOKUS-covered canton name. One of
|
election_nr |
Election number. A positive integerish scalar. |
past |
Whether to process the current or the predecessor election's parties. |
strict |
Whether or not to strictly ensure that all of |
A factor.
election_parties()
d <- fokus::read_survey_data(ballot_date = "2024-10-20",
canton = "aargau",
lang = "de")
# before
levels(d$voting_decision_cantonal_proportional_election_1_party)
fct_new <- fct_relabel_election_parties(
fct = d$voting_decision_cantonal_proportional_election_1_party,
to_type = "short",
ballot_date = "2024-10-20",
lvl = "cantonal",
canton = "aargau",
election_nr = 1L,
past = FALSE
)
# after
levels(fct_new)
# set `strict = FALSE` if your factor contains non-standard levels
d$voting_decision_cantonal_proportional_election_1_party |>
forcats::fct_lump_min(other_level = "Kleinparteien",
min = 5L) |>
fct_relabel_election_parties(to_type = "short",
ballot_date = "2024-10-20",
lvl = "cantonal",
canton = "aargau",
election_nr = 1L,
past = FALSE,
strict = FALSE) |>
levels()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.