Skip to contents

Augments data with an additional column turnout containing the voter turnout calculated as:

votes_yes+votes_no+votes_empty+votes_invalidelectorate_total\frac{votes\_yes+votes\_no+votes\_empty+votes\_invalid}{electorate\_total}

Usage

add_turnout(data, rough = TRUE, excl_dubious = TRUE)

Arguments

data

RDB referendum data as returned by rfrnds(). A data frame that at minimum contains the columns electorate_total, votes_yes, votes_no, votes_empty and votes_invalid.

rough

Whether to fall back on a "rough" calculation of the turnout in case any of the variables votes_empty or votes_invalid is unknown (NA), or to be strict and return NA in such a case.

excl_dubious

Whether or not to exclude obviously dubious turnout numbers (those > 1.0) by setting them to NA. Such numbers stem either from data errors or (officially) tampered numbers.

Value

A tibble.

Examples

# rough turnout numbers
rdb::rfrnds(quiet = TRUE) |>
  rdb::add_turnout() |>
  dplyr::select(id,
                electorate_total,
                starts_with("votes_"),
                turnout)
#> # A tibble: 17,889 × 8
#>    id                       electorate_total votes_yes votes_no votes_empty votes_invalid votes_per_subterritory turnout
#>    <chr>                               <int>     <int>    <int>       <int>         <int> <list>                   <dbl>
#>  1 670cd145c3cd67046058015c            76411     16019    23569         318           490 <NULL>                   0.529
#>  2 66fff490c3cd670460580111            21114      6920     5481          23           225 <NULL>                   0.599
#>  3 66ffdfe3c3cd6704605800fc            54688     19470     7253         644           125 <NULL>                   0.503
#>  4 66f686cfc3cd6704605800a0            64092     20941     2928         754            37 <NULL>                   0.385
#>  5 66f68317c3cd67046058009c           749365    264717    40600       13410           638 <NULL>                   0.426
#>  6 66d6da9cc3cd670460580053            78268     46549    28802        1905          1012 <NULL>                   1    
#>  7 66cde603c3cd67046057fff5            56927     42607    12563        1037           720 <NULL>                   1    
#>  8 66c46f86c3cd67046057ff53           108212     27024    25152         424            30 <NULL>                   0.486
#>  9 66c46cf6c3cd67046057ff4f           183598     49060    20304        2644           930 <NULL>                   0.397
#> 10 66c46c3ac3cd67046057ff4b           183598     51469    17569        2793           936 <NULL>                   0.396
#> # ℹ 17,879 more rows

# strict turnout numbers
rdb::rfrnds(quiet = TRUE) |>
  rdb::add_turnout(rough = FALSE) |>
  dplyr::select(id,
                electorate_total,
                starts_with("votes_"),
                turnout)
#> # A tibble: 17,889 × 8
#>    id                       electorate_total votes_yes votes_no votes_empty votes_invalid votes_per_subterritory turnout
#>    <chr>                               <int>     <int>    <int>       <int>         <int> <list>                   <dbl>
#>  1 670cd145c3cd67046058015c            76411     16019    23569         318           490 <NULL>                   0.529
#>  2 66fff490c3cd670460580111            21114      6920     5481          23           225 <NULL>                   0.599
#>  3 66ffdfe3c3cd6704605800fc            54688     19470     7253         644           125 <NULL>                   0.503
#>  4 66f686cfc3cd6704605800a0            64092     20941     2928         754            37 <NULL>                   0.385
#>  5 66f68317c3cd67046058009c           749365    264717    40600       13410           638 <NULL>                   0.426
#>  6 66d6da9cc3cd670460580053            78268     46549    28802        1905          1012 <NULL>                   1    
#>  7 66cde603c3cd67046057fff5            56927     42607    12563        1037           720 <NULL>                   1    
#>  8 66c46f86c3cd67046057ff53           108212     27024    25152         424            30 <NULL>                   0.486
#>  9 66c46cf6c3cd67046057ff4f           183598     49060    20304        2644           930 <NULL>                   0.397
#> 10 66c46c3ac3cd67046057ff4b           183598     51469    17569        2793           936 <NULL>                   0.396
#> # ℹ 17,879 more rows