Skip to contents

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.

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)
#>  [1] "keine (leer eingelegt oder nicht teilgenommen)"               "Schweizerische Volkspartei (SVP)"                            
#>  [3] "Sozialdemokratische Partei (SP) und JUSO"                     "FDP.Die Liberalen und Jungfreisinnige"                       
#>  [5] "Die Mitte.Miteinander.Für den Aargau."                        "Grüne und Junge Grüne"                                       
#>  [7] "Grünliberale Partei (GLP)"                                    "Evangelische Volkspartei (EVP)"                              
#>  [9] "Eidgenössisch-Demokratische Union (EDU)"                      "Lösungs-Orientierte Volks-Bewegung (LOVB)"                   
#> [11] "Piratenpartei Aargau (PPAG)"                                  "Fit – Freiheit"                                              
#> [13] "NB – Neues Bewusstsein"                                       "DBP – DieBürgerPartei"                                       
#> [15] "MASS-VOLL! Bewegung für Freiheit, Souveränität & Grundrechte" "Musikpartei"                                                 

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)
#>  [1] "keine"                 "SVP"                   "SP / JUSO"             "FDP / Jungfreisinnige" "Mitte"                 "Grüne / Junge Grüne"  
#>  [7] "GLP"                   "EVP"                   "EDU"                   "LOVB"                  "PPAG"                  "Fit"                  
#> [13] "NB"                    "DBP"                   "MASSVOLL"              "Musik"                

# 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()
#>  [1] "keine"                 "SVP"                   "SP / JUSO"             "FDP / Jungfreisinnige" "Mitte"                 "Grüne / Junge Grüne"  
#>  [7] "GLP"                   "EVP"                   "EDU"                   "MASSVOLL"              "Kleinparteien"