as_ballot_dates | R Documentation |
Transforms referendum-level observations to ones on the level of ballot date and jurisdiction via nesting of referendum-level columns. The
individual values of all the referendums on a specific ballot date in a specific jurisdiction are preserved in a list column named rfrnd_data
.
as_ballot_dates(data, cols_to_retain = NULL)
data |
RDB referendum data as returned by |
cols_to_retain |
Additional non-standard columns to be preserved as top-level columns instead of being nested in the list column |
A tibble.
Other referendum data transformation functions:
n_rfrnds()
,
n_rfrnds_per_period()
,
prettify_col_names()
,
unnest_var()
# standard RDB columns are retained as far as possible
rdb::rfrnds(quiet = TRUE) |>
rdb::as_ballot_dates()
# non-standard columns must be explicitly specified in order to be retained
data_rdb <-
rdb::rfrnds(quiet = TRUE) |>
rdb::add_world_regions() |>
dplyr::mutate(region_custom =
factor(x = dplyr::if_else(country_code == "CH",
"Switzerland & Liechtenstein",
un_region_tier_1_name),
levels = c("Switzerland & Liechtenstein",
levels(un_region_tier_1_name))) |>
forcats::fct_relevel("Switzerland & Liechtenstein",
after = 3L) |>
forcats::fct_recode("rest of Europe" = "Europe"))
data_rdb |> rdb::as_ballot_dates() |> colnames()
data_rdb |> rdb::as_ballot_dates(cols_to_retain = region_custom) |> colnames()
# non-standard columns to retain must actually be retainable
try(
data_rdb |> rdb::as_ballot_dates(cols_to_retain = title_en)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.