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,893 × 3
#>    id                       date        week
#>    <chr>                    <date>     <int>
#>  1 675aa6786053de6f432eefa8 2024-09-22    38
#>  2 670cd145c3cd67046058015c 2024-06-09    23
#>  3 66fff490c3cd670460580111 2024-09-22    38
#>  4 66ffdfe3c3cd6704605800fc 2024-09-22    38
#>  5 66ffdc31c3cd6704605800ee 2024-09-22    38
#>  6 66ffd956c3cd6704605800ec 2024-09-22    38
#>  7 66ffbf93c3cd6704605800df 2024-09-22    38
#>  8 66f686cfc3cd6704605800a0 2024-09-22    38
#>  9 66f68317c3cd67046058009c 2024-09-22    38
#> 10 66d6da9cc3cd670460580053 2024-09-22    38
#> # ℹ 17,883 more rows

rdb::rfrnds(quiet = TRUE) |>
  rdb::add_period("year") |>
  dplyr::select(id, date, year)
#> # A tibble: 17,893 × 3
#>    id                       date        year
#>    <chr>                    <date>     <int>
#>  1 675aa6786053de6f432eefa8 2024-09-22  2024
#>  2 670cd145c3cd67046058015c 2024-06-09  2024
#>  3 66fff490c3cd670460580111 2024-09-22  2024
#>  4 66ffdfe3c3cd6704605800fc 2024-09-22  2024
#>  5 66ffdc31c3cd6704605800ee 2024-09-22  2024
#>  6 66ffd956c3cd6704605800ec 2024-09-22  2024
#>  7 66ffbf93c3cd6704605800df 2024-09-22  2024
#>  8 66f686cfc3cd6704605800a0 2024-09-22  2024
#>  9 66f68317c3cd67046058009c 2024-09-22  2024
#> 10 66d6da9cc3cd670460580053 2024-09-22  2024
#> # ℹ 17,883 more rows