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 inperiodor the columndate(to compute the period column), plus the one(s) specified viaby(if any).- by
Up to two additional
datacolumns 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
periodgaps indata.- period_floor
Lower
periodlimit up to which gaps are filled. IfNULL, the lower limit is set to the minimum ofperiodpresent indata. Only relevant iffill_gaps = TRUEandperiodis set to a unique timespan type ("year","decade"or"century").- period_ceiling
Upper
periodlimit up to which gaps are filled. IfNULL, the upper limit is set to the maximum ofperiodpresent indata. Only relevant iffill_gaps = TRUEandperiodis 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
periodin 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 inby.- 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 ifbyis 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()orgt::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()orgt::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
2010s
2000s
1990s
1980s
1970s
1960s
1950s
1940s
1930s
1920s
1910s
1900s
1890s
1880s
1870s
1860s
1850s
1840s
1830s
1820s
1810s
1800s
1790s
Total
# grouped by a single additional column
rdb::rfrnds(quiet = TRUE) |>
rdb::tbl_n_rfrnds_per_period(by = level,
period = "decade")
local
subnational
national
Total
2020s
2010s
2000s
1990s
1980s
1970s
1960s
1950s
1940s
1930s
1920s
1910s
1900s
1890s
1880s
1870s
1860s
1850s
1840s
1830s
1820s
1810s
1800s
1790s
Total
# grouped by two addtional columns
rdb::rfrnds(quiet = TRUE) |>
rdb::tbl_n_rfrnds_per_period(by = c(level, type),
period = "decade")
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
2010s
2000s
1990s
1980s
1970s
1960s
1950s
1940s
1930s
1920s
1910s
1900s
1890s
1880s
1870s
1860s
1850s
1840s
1830s
1820s
1810s
1800s
1790s
Total
# count ballot dates instead of referendums
rdb::rfrnds(quiet = TRUE) |>
rdb::as_ballot_dates() |>
rdb::tbl_n_rfrnds_per_period(period = "decade")
n
2020s
2010s
2000s
1990s
1980s
1970s
1960s
1950s
1940s
1930s
1920s
1910s
1900s
1890s
1880s
1870s
1860s
1850s
1840s
1830s
1820s
1810s
1800s
1790s
Total