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_per_period(), n_rfrnds(), prettify_col_names()

Other variable unnesting functions: var_name_unnested()

Examples

rdb::rfrnds(quiet = TRUE) |>
  rdb::unnest_var(topics_tier_2)
#> # A tibble: 23,131 × 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 65096e84481d… NA          pl0120… PL           Poland       NA                     NA           nati… 2023-10-15 NA                Privati… Privati… NA      
#>  2 65096dc1481d… NA          pl0220… PL           Poland       NA                     NA           nati… 2023-10-15 NA                raising… Anhebun… NA      
#>  3 65096535481d… NA          pl0320… PL           Poland       NA                     NA           nati… 2023-10-15 NA                Removal… Abbau d… NA      
#>  4 6509625d481d… NA          pl0420… PL           Poland       NA                     NA           nati… 2023-10-15 NA                Europea… Beschlu… NA      
#>  5 650034e4481d… NA          au0120… AU           Australia    NA                     NA           nati… 2023-10-14 NA                Establi… Stimme … NA      
#>  6 650034e4481d… NA          au0120… AU           Australia    NA                     NA           nati… 2023-10-14 NA                Establi… Stimme … NA      
#>  7 64e46f7a481d… NA          ec0920… EC           Ecuador      NA                     NA           nati… 2023-08-20 NA                No crud… Keine R… NA      
#>  8 64e46c8f481d… NA          fm0820… FM           Micronesia   NA                     NA           nati… 2023-07-04 NA                Indepen… Unabhän… NA      
#>  9 64e46c8f481d… NA          fm0820… FM           Micronesia   NA                     NA           nati… 2023-07-04 NA                Indepen… Unabhän… NA      
#> 10 64c8b3ca0b8b… NA          fm0720… FM           Micronesia   NA                     NA           nati… 2023-07-04 NA                Providi… NA       NA      
#> # ℹ 23,121 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>, …