Skip to contents

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

Usage

unnest_var(data, var)

Arguments

data

RDB referendum data as returned by rfrnds(). A data frame that at minimum contains the column specified in var.

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,294 × 67
#>    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 675aa6786053… NA          NA      CH           Switzerland  Geneva                 NA           subn… 2024-09-22 NA                An Act … NA       Loi mod…
#>  2 670cd145c3cd… NA          NA      CH           Switzerland  Zug                    NA           subn… 2024-06-09 NA                Cycling… Velonet… NA      
#>  3 66fff490c3cd… NA          NA      LI           Liechtenste… NA                     NA           nati… 2024-09-22 NA                Referen… Referen… NA      
#>  4 66ffdfe3c3cd… NA          NA      CH           Switzerland  Jura                   NA           subn… 2024-09-22 NA                Act con… NA       Acte re…
#>  5 66ffdc31c3cd… NA          NA      CH           Switzerland  Uri                    NA           subn… 2024-09-22 NA                Energy … Energie… NA      
#>  6 66ffdc31c3cd… NA          NA      CH           Switzerland  Uri                    NA           subn… 2024-09-22 NA                Energy … Energie… NA      
#>  7 66ffd956c3cd… NA          NA      CH           Switzerland  Uri                    NA           subn… 2024-09-22 NA                Partial… Teilrev… NA      
#>  8 66ffbf93c3cd… NA          NA      CH           Switzerland  Nidwalden              NA           subn… 2024-09-22 NA                Amendme… Änderun… NA      
#>  9 66ffbf93c3cd… NA          NA      CH           Switzerland  Nidwalden              NA           subn… 2024-09-22 NA                Amendme… Änderun… NA      
#> 10 66f686cfc3cd… NA          NA      CH           Switzerland  Bern                   NA           subn… 2024-09-22 NA                Concord… Konkord… NA      
#> # ℹ 23,284 more rows
#> # ℹ abbreviated name: ¹​subnational_entity_name
#> # ℹ 54 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>, sources <chr>, is_draft <lgl>,
#> #   date_time_created <dttm>, date_time_last_edited <dttm>, type <fct>, inst_legal_basis_type <ord>, inst_has_urgent_legal_basis <lgl>, …