Unnests a multi-value variable of type list to long format. Multi-value variables can contain more than one value per observation and thus break with the
tidy-data convention. This function allows to conveniently expand data
to contain a single var
value per observation only, thereby increasing the number of observations (i.e. rows).
Arguments
- data
RDB referendum data as returned by
rfrnds()
. A data frame that at minimum contains the column specified invar
.- var
data
column to unnest. One of the multi-value variables:topics_tier_1
topics_tier_2
topics_tier_3
inst_object_revision_modes
inst_topics_only
inst_topics_excluded
Tidy selections are supported.
Value
A tibble.
See also
Other referendum data transformation functions:
as_ballot_dates()
,
n_rfrnds()
,
n_rfrnds_per_period()
,
prettify_col_names()
Other variable unnesting functions:
var_name_unnested()
Examples
rdb::rfrnds(quiet = TRUE) |>
rdb::unnest_var(topics_tier_2)
#> # A tibble: 23,288 × 69
#> id id_official id_sudd country_code country_name subnational_entity_n…¹ municipality level date is_former_country title_en title_de title_fr
#> <chr> <chr> <chr> <fct> <fct> <chr> <chr> <ord> <date> <lgl> <chr> <chr> <chr>
#> 1 670cd145c3cd… NA NA CH Switzerland Zug NA subn… 2024-06-09 NA Cycling… Velonet… NA
#> 2 66fff490c3cd… NA NA LI Liechtenste… NA NA nati… 2024-09-22 NA Referen… Referen… NA
#> 3 66ffdfe3c3cd… NA NA CH Switzerland Jura NA subn… 2024-09-22 NA Act con… NA Acte re…
#> 4 66f686cfc3cd… NA NA CH Switzerland Bern NA subn… 2024-09-22 NA Concord… Konkord… NA
#> 5 66f68317c3cd… NA NA CH Switzerland Bern NA subn… 2024-09-22 NA Amendme… Änderun… NA
#> 6 66f68317c3cd… NA NA CH Switzerland Bern NA subn… 2024-09-22 NA Amendme… Änderun… NA
#> 7 66d6da9cc3cd… NA NA CH Switzerland Basel Landschaft NA subn… 2024-09-22 NA Partial… Teilrev… NA
#> 8 66d6da9cc3cd… NA NA CH Switzerland Basel Landschaft NA subn… 2024-09-22 NA Partial… Teilrev… NA
#> 9 66d6da9cc3cd… NA NA CH Switzerland Basel Landschaft NA subn… 2024-09-22 NA Partial… Teilrev… NA
#> 10 66cde603c3cd… NA NA CH Switzerland Graubünden NA subn… 2024-09-22 NA New civ… Neubau … NA
#> # ℹ 23,278 more rows
#> # ℹ abbreviated name: ¹subnational_entity_name
#> # ℹ 56 more variables: question <chr>, question_en <chr>, committee_name <chr>, result <fct>, subterritories_yes <dbl>, subterritories_no <dbl>,
#> # electorate_total <int>, electorate_abroad <int>, votes_yes <int>, votes_no <int>, votes_empty <int>, votes_invalid <int>, votes_per_subterritory <list>,
#> # lower_house_yes <int>, lower_house_no <int>, lower_house_abstentions <int>, upper_house_yes <int>, upper_house_no <int>, upper_house_abstentions <int>,
#> # position_government <fct>, topics_tier_1 <list>, topic_tier_2 <fct>, topics_tier_3 <list>, remarks <chr>, files <list>, url_sudd <chr>,
#> # url_swissvotes <chr>, sources <chr>, is_draft <lgl>, date_time_created <dttm>, date_time_last_edited <dttm>, type <fct>, inst_legal_basis_type <ord>, …