Skip to contents

Creates a ready-to-print gt table with the number of referendums, optionally counted by up to three additional variables.

Usage

tbl_n_rfrnds(
  data,
  by = NULL,
  complete_fcts = TRUE,
  n_rows = Inf,
  order = NULL,
  incl_row_head = TRUE,
  incl_col_head = TRUE,
  add_total_row = NULL,
  add_total_col = NULL,
  lbl_total_row = gt::md("**Total**"),
  lbl_total_col = gt::md("**Total**")
)

Arguments

data

RDB referendum data as returned by rfrnds(). A data frame that at minimum contains the columns specified in by (if any).

by

Up to three additional data columns to group by before counting number of referendums. Tidy selections are supported.

complete_fcts

Whether or not to complete the result with implicitly missing combinations of those columns specified in by which are of type factor.

n_rows

Maximum number of rows to be included in the resulting table. All the rows exceeding that limit are replaced by a single row of ellipses. An integer scalar or Inf for an unlimited number of rows.

order

How to order the rows of the resulting table. One of

  • "ascending" to sort in ascending order by the number of referendums,

  • "descending" to sort in descending order by the number of referendums, or

  • NULL to leave the sorting unchanged.

incl_row_head

Whether or not to include a row heading with the prettified name of the first by variable.

incl_col_head

Whether or not to include column headings (in the table's stub) with the prettified names of the second and third by variables.

add_total_row

Whether or not to add a summary row at the very end of the table containing column totals. If NULL, a total row is added only if at least one column is provided in by.

add_total_col

Whether or not to add a summary column at the very end of the table containing row totals. If NULL, a total column is added only if multiple columns are provided in by.

lbl_total_row

Label of the summary row containing column totals. Only relevant if add_total_row = TRUE. A character scalar. gt::md() or gt::html() can be used to format the label text.

lbl_total_col

Label of the summary column containing row totals. Only relevant if add_total_col = TRUE. A character scalar. gt::md() or gt::html() can be used to format the label text.

Value

A gt_tbl object.

Details

The first variable specified in by will be reflected in additional rows in the resulting table, i.e. expand it vertically. The second and third variables will be reflected in additional columns, i.e. expand it horizontally.

See also

Other tabulation functions: tbl_n_rfrnds_per_period()

Examples

rdb::rfrnds(quiet = TRUE) |>
  rdb::tbl_n_rfrnds()
17893
# grouped by a single column rdb::rfrnds(quiet = TRUE) |> rdb::tbl_n_rfrnds(by = level)
Political level
local 43
subnational 14715
national 3135
Total 17893
# grouped by two columns rdb::rfrnds(quiet = TRUE) |> rdb::tbl_n_rfrnds(by = c(type, level))
Political level local subnational national Total
Type
mandatory referendum 6 3665 1097 4768
optional referendum 13 5158 399 5570
counter proposal 0 253 48 301
citizens’ initiative 0 3909 452 4361
governmental referendum 9 343 1099 1451
citizens’ assembly 0 715 0 715
recall 0 0 2 2
N/A 15 672 38 725
Total 43 14715 3135 17893
# grouped by three columns rdb::rfrnds(quiet = TRUE) |> rdb::tbl_n_rfrnds(by = c(country_name, level, type), n_rows = 10L, order = "descending")
Political level

Type
local
subnational
national
Total
mandatory referendum optional referendum counter proposal citizens' initiative governmental referendum citizens' assembly recall N/A mandatory referendum optional referendum counter proposal citizens' initiative governmental referendum citizens' assembly recall N/A mandatory referendum optional referendum counter proposal citizens' initiative governmental referendum citizens' assembly recall N/A
Country
Switzerland 0 0 0 0 0 0 0 1 3410 884 245 1036 188 715 0 447 203 209 41 234 1 0 0 1 7615
United States 0 0 0 0 0 0 0 0 193 4224 0 2840 6 0 0 79 0 0 0 0 0 0 0 0 7342
Italy 0 13 0 0 0 0 0 0 0 17 0 4 2 0 0 4 0 77 0 0 11 0 0 0 128
New Zealand 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 96 1 0 4 25 0 0 0 128
Liechtenstein 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 35 6 41 39 0 0 0 121
Northern Mariana Islands 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 94 0 0 2 13 0 0 1 113
Micronesia 0 0 0 0 2 0 0 0 0 0 0 0 24 0 0 2 65 0 0 4 6 0 0 0 103
Germany 0 0 0 0 0 0 0 0 21 7 8 25 0 0 0 29 0 3 0 2 5 0 0 0 100
Ecuador 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 0 0 1 68 0 0 0 83
Australia 0 0 0 0 0 0 0 0 0 5 0 0 3 0 0 17 44 0 0 0 10 0 0 0 79
Total 6 13 0 0 9 0 0 15 3665 5158 253 3909 343 715 0 672 1097 399 48 452 1099 0 2 38 17893
# count ballot dates instead of referendums rdb::rfrnds(quiet = TRUE) |> rdb::as_ballot_dates() |> rdb::tbl_n_rfrnds(by = c(country_name, level), n_rows = 10L, order = "descending")
Political level local subnational national Total
Country
Switzerland 1 2708 327 3036
United States 0 1252 0 1252
Liechtenstein 0 0 92 92
Germany 0 59 9 68
Italy 5 20 33 58
New Zealand 0 2 46 48
Australia 0 20 25 45
France 2 16 27 45
Canada 0 33 3 36
Ireland 0 0 32 32
Total 22 4285 1633 5940