tbl_n_rfrnds: Tabulate number of referendums

tbl_n_rfrndsR Documentation

Tabulate number of referendums

Description

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.

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.

Value

A gt_tbl object.

See Also

Other tabulation functions: tbl_n_rfrnds_per_period()

Examples

rdb::rfrnds(quiet = TRUE) |>
  rdb::tbl_n_rfrnds()

# grouped by a single column
rdb::rfrnds(quiet = TRUE) |>
  rdb::tbl_n_rfrnds(by = level)

# grouped by two columns
rdb::rfrnds(quiet = TRUE) |>
  rdb::tbl_n_rfrnds(by = c(type, level))

# grouped by three columns
rdb::rfrnds(quiet = TRUE) |>
  rdb::tbl_n_rfrnds(by = c(country_name, level, type),
                    n_rows = 10L,
                    order = "descending")

# 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")

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