Skip to contents

Augments data with an additional column holding the specified period in which the referendum took place. The new column is named after period and its values are always of type integer.

Usage

add_period(
  data,
  period = c("week", "month", "quarter", "year", "decade", "century")
)

Arguments

data

RDB referendum data as returned by rfrnds(). A data frame that at minimum contains the column date.

period

Type of period to add. One of "week", "month", "quarter", "year", "decade" or "century".

Value

A tibble.

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

Examples

rdb::rfrnds(quiet = TRUE) |>
  rdb::add_period() |>
  dplyr::select(id, date, week)
#> # A tibble: 17,766 × 3
#>    id                       date        week
#>    <chr>                    <date>     <int>
#>  1 65096e84481d20233932cc70 2023-10-15    41
#>  2 65096dc1481d20233932cc6e 2023-10-15    41
#>  3 65096535481d20233932cc66 2023-10-15    41
#>  4 6509625d481d20233932cc63 2023-10-15    41
#>  5 650034e4481d20233932cc39 2023-10-14    41
#>  6 64e46f7a481d20233932cc0b 2023-08-20    33
#>  7 64e46c8f481d20233932cc09 2023-07-04    27
#>  8 64c8b3ca0b8bae0c78c7ec8a 2023-07-04    27
#>  9 64c8b19c0b8bae0c78c7ec86 2023-07-04    27
#> 10 64c8a28d0b8bae0c78c7ec82 2023-07-04    27
#> # ℹ 17,756 more rows

rdb::rfrnds(quiet = TRUE) |>
  rdb::add_period("year") |>
  dplyr::select(id, date, year)
#> # A tibble: 17,766 × 3
#>    id                       date        year
#>    <chr>                    <date>     <int>
#>  1 65096e84481d20233932cc70 2023-10-15  2023
#>  2 65096dc1481d20233932cc6e 2023-10-15  2023
#>  3 65096535481d20233932cc66 2023-10-15  2023
#>  4 6509625d481d20233932cc63 2023-10-15  2023
#>  5 650034e4481d20233932cc39 2023-10-14  2023
#>  6 64e46f7a481d20233932cc0b 2023-08-20  2023
#>  7 64e46c8f481d20233932cc09 2023-07-04  2023
#>  8 64c8b3ca0b8bae0c78c7ec8a 2023-07-04  2023
#>  9 64c8b19c0b8bae0c78c7ec86 2023-07-04  2023
#> 10 64c8a28d0b8bae0c78c7ec82 2023-07-04  2023
#> # ℹ 17,756 more rows