tbl_n_rfrnds_per_period: Tabulate number of referendums per period

tbl_n_rfrnds_per_periodR Documentation

Tabulate number of referendums per period

Description

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.

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).

Value

A gt_tbl object.

See Also

Other tabulation functions: tbl_n_rfrnds()

Examples

rdb::rfrnds(quiet = TRUE) |>
  rdb::tbl_n_rfrnds_per_period(period = "decade")

# grouped by a single additional column
rdb::rfrnds(quiet = TRUE) |>
  rdb::tbl_n_rfrnds_per_period(by = level,
                               period = "decade")

# grouped by two addtional columns
rdb::rfrnds(quiet = TRUE) |>
  rdb::tbl_n_rfrnds_per_period(by = c(level, type),
                               period = "decade")

# count ballot dates instead of referendums
rdb::rfrnds(quiet = TRUE) |>
  rdb::as_ballot_dates() |>
  rdb::tbl_n_rfrnds_per_period(period = "decade")

zdaarau/c2d documentation built on Dec. 18, 2024, 1:24 p.m.