n_rfrnds_per_period: Count number of referendums per period

n_rfrnds_per_periodR Documentation

Count number of referendums per period

Description

Counts the number of RDB referendums per desired period, optionally by additional columns specified via by.

Usage

n_rfrnds_per_period(
  data,
  by = NULL,
  period = c("week", "month", "quarter", "year", "decade", "century"),
  fill_gaps = TRUE,
  period_floor = NULL,
  period_ceiling = NULL,
  descending = FALSE
)

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

Optional data column(s) 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").

descending

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

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

See Also

Other referendum data transformation functions: as_ballot_dates(), n_rfrnds(), prettify_col_names(), unnest_var()

Examples

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

rdb::rfrnds(quiet = TRUE) |>
  rdb::n_rfrnds_per_period(by = level)

# without filling gaps
rdb::rfrnds(quiet = TRUE) |>
  rdb::n_rfrnds_per_period(by = level,
                           fill_gaps = FALSE)

# per decade and by multiple columns
rdb::rfrnds(quiet = TRUE) |>
  rdb::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::n_rfrnds_per_period()

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