Skip to contents

Creates a ready-to-print gt table with the number of referendums per period, optionally counted by up to two additional columns.

Usage

tbl_n_rfrnds_per_period(
  data,
  by = NULL,
  period = c("week", "month", "quarter", "year", "decade", "century"),
  fill_gaps = TRUE,
  period_floor = NULL,
  period_ceiling = NULL,
  squeeze_zero_rows = TRUE,
  descending = TRUE,
  add_total_row = TRUE,
  add_total_col = NULL,
  lbl_total_row = gt::md("**Total**"),
  lbl_total_col = lbl_total_row
)

Arguments

data

RDB referendum data as returned by rfrnds(). A data frame that at minimum contains the column specified in period or the column date (to compute the period column), plus the one(s) specified via by (if any).

by

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

period

Type of period to count referendums by. One of "week", "month", "quarter", "year", "decade" or "century".

fill_gaps

Whether or not to add zero-value rows to the result for period gaps in data.

period_floor

Lower period limit up to which gaps are filled. If NULL, the lower limit is set to the minimum of period present in data. Only relevant if fill_gaps = TRUE and period is set to a unique timespan type ("year", "decade" or "century").

period_ceiling

Upper period limit up to which gaps are filled. If NULL, the upper limit is set to the maximum of period present in data. Only relevant if fill_gaps = TRUE and period is set to a unique timespan type ("year", "decade" or "century").

squeeze_zero_rows

Whether or not to compress consecutive zero-sum rows into single period span rows.

descending

Whether to sort the resulting table by period in descending or in ascending order.

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 by is non-empty.

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

Note that the period types "year", "decade" and "century" are unique timespans, while "week", "month" and "quarter" are recurring timespans (e.g. every year has a week 1).

See also

Other tabulation functions: tbl_n_rfrnds()

Examples

rdb::rfrnds(quiet = TRUE) |>
  rdb::tbl_n_rfrnds_per_period(period = "decade")
n
2020s 506
2010s 1500
2000s 2982
1990s 3453
1980s 2758
1970s 2685
1960s 723
1950s 544
1940s 498
1930s 589
1920s 578
1910s 633
1900s 178
1890s 68
1880s 19
1870s 23
1860s 64
1850s 6
1840s 25
1830s 7
1820s 6
1810s 5
1800s 14
1790s 29
Total 17893
# grouped by a single additional column rdb::rfrnds(quiet = TRUE) |> rdb::tbl_n_rfrnds_per_period(by = level, period = "decade")
Political level local subnational national Total
2020s 0 326 180 506
2010s 0 1071 429 1500
2000s 16 2490 476 2982
1990s 2 2841 610 3453
1980s 0 2441 317 2758
1970s 0 2386 299 2685
1960s 6 546 171 723
1950s 0 407 137 544
1940s 4 405 89 498
1930s 0 498 91 589
1920s 0 490 88 578
1910s 0 577 56 633
1900s 0 142 36 178
1890s 0 30 38 68
1880s 0 7 12 19
1870s 1 1 21 23
1860s 1 18 45 64
1850s 0 1 5 6
1840s 12 8 5 25
1830s 0 7 0 7
1820s 0 6 0 6
1810s 0 1 4 5
1800s 0 3 11 14
1790s 1 13 15 29
Total 43 14715 3135 17893
# grouped by two addtional columns rdb::rfrnds(quiet = TRUE) |> rdb::tbl_n_rfrnds_per_period(by = c(level, type), period = "decade")
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
2020s 0 0 0 0 0 0 0 0 148 66 22 76 14 0 0 0 58 37 0 31 54 0 0 0 506
2010s 0 0 0 0 0 0 0 0 347 226 82 277 86 28 0 25 113 61 6 104 137 0 0 8 1500
2000s 0 0 0 0 2 0 0 14 544 1048 33 561 89 118 0 97 163 68 7 97 137 0 2 2 2982
1990s 0 0 0 0 1 0 0 1 822 974 41 645 47 165 0 147 216 82 3 73 232 0 0 4 3453
1980s 0 0 0 0 0 0 0 0 824 576 37 672 14 172 0 146 159 35 8 38 70 0 0 7 2758
1970s 0 0 0 0 0 0 0 0 855 631 38 444 35 232 0 151 115 24 8 28 121 0 0 3 2685
1960s 6 0 0 0 0 0 0 0 4 370 0 134 7 0 0 31 52 12 1 15 89 0 0 2 723
1950s 0 0 0 0 0 0 0 0 5 263 0 126 2 0 0 11 47 16 5 14 52 0 0 3 544
1940s 0 0 0 0 4 0 0 0 6 193 0 178 10 0 0 18 28 8 2 10 41 0 0 0 498
1930s 0 0 0 0 0 0 0 0 3 230 0 254 2 0 0 9 24 13 3 12 34 0 0 5 589
1920s 0 0 0 0 0 0 0 0 1 268 0 195 7 0 0 19 36 11 4 20 15 0 0 2 578
1910s 0 0 0 0 0 0 0 0 15 272 0 282 5 0 0 3 29 2 0 3 22 0 0 0 633
1900s 0 0 0 0 0 0 0 0 54 19 0 65 4 0 0 0 15 5 1 4 11 0 0 0 178
1890s 0 0 0 0 0 0 0 0 30 0 0 0 0 0 0 0 19 9 0 3 7 0 0 0 68
1880s 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 4 8 0 0 0 0 0 0 19
1870s 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 3 8 0 0 10 0 0 0 23
1860s 0 1 0 0 0 0 0 0 0 8 0 0 2 0 0 8 11 0 0 0 34 0 0 0 64
1850s 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 5 0 0 0 6
1840s 0 12 0 0 0 0 0 0 0 5 0 0 3 0 0 0 2 0 0 0 3 0 0 0 25
1830s 0 0 0 0 0 0 0 0 0 3 0 0 4 0 0 0 0 0 0 0 0 0 0 0 7
1820s 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 1 0 0 0 0 0 0 0 0 6
1810s 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 4 0 0 0 5
1800s 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 1 0 0 0 10 0 0 0 14
1790s 0 0 0 0 1 0 0 0 0 3 0 0 6 0 0 4 2 0 0 0 11 0 0 2 29
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_per_period(period = "decade")
n
2020s 249
2010s 704
2000s 1001
1990s 1062
1980s 844
1970s 873
1960s 243
1950s 188
1940s 153
1930s 162
1920s 158
1910s 112
1900s 38
1890s 29
1880s 11
1870s 20
1860s 28
1850s 6
1840s 12
1830s 3
1820s 3
1810s 5
1800s 12
1790s 24
Total 5940