fct_relabel_election_parties: Relabel factor of election parties

fct_relabel_election_partiesR Documentation

Relabel factor of election parties

Description

Relabels a factor that contains election parties from/to the different FOKUS election party name types.

Usage

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
)

Arguments

fct

Factor to be relabelled.

from_type

Name type to convert from. One of "qstnr", "run" or "short".

to_type

Name type to convert to. One of "short", "run" or "qstnr".

ballot_date

FOKUS-covered ballot date. One of

  • "2018-09-23"

  • "2018-11-25"

  • "2019-10-20"

  • "2020-09-27"

  • "2020-10-18"

  • "2021-11-28"

  • "2023-06-18"

  • "2024-10-20"

lvl

Political level. One of "cantonal" or "federal".

canton

FOKUS-covered canton name. One of

  • "aargau"

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 fct levels are matched by known election parties.

Value

A factor.

See Also

election_parties()

Examples

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()

zdaarau/fokus documentation built on Dec. 24, 2024, 10:47 p.m.