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 columndate
.- 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).
See also
Other referendum data augmentation functions:
add_country_code_continual()
,
add_country_code_long()
,
add_country_name()
,
add_country_name_long()
,
add_former_country_flag()
,
add_turnout()
,
add_urls()
,
add_world_regions()
Examples
rdb::rfrnds(quiet = TRUE) |>
rdb::add_period() |>
dplyr::select(id, date, week)
#> # A tibble: 17,866 × 3
#> id date week
#> <chr> <date> <int>
#> 1 6694f97dc3cd67046057fed1 2024-06-09 23
#> 2 66856a7bc3cd67046057fe61 2024-06-09 23
#> 3 66856972c3cd67046057fe5a 2024-06-09 23
#> 4 66856835c3cd67046057fe53 2024-06-09 23
#> 5 66856659c3cd67046057fe4b 2024-06-09 23
#> 6 6659b208c3cd67046057fe31 2024-06-09 23
#> 7 6659b140c3cd67046057fe2d 2024-06-09 23
#> 8 6659af29c3cd67046057fe29 2024-06-09 23
#> 9 6659ae82c3cd67046057fe25 2024-06-09 23
#> 10 6659ad59c3cd67046057fe21 2024-06-09 23
#> # ℹ 17,856 more rows
rdb::rfrnds(quiet = TRUE) |>
rdb::add_period("year") |>
dplyr::select(id, date, year)
#> # A tibble: 17,866 × 3
#> id date year
#> <chr> <date> <int>
#> 1 6694f97dc3cd67046057fed1 2024-06-09 2024
#> 2 66856a7bc3cd67046057fe61 2024-06-09 2024
#> 3 66856972c3cd67046057fe5a 2024-06-09 2024
#> 4 66856835c3cd67046057fe53 2024-06-09 2024
#> 5 66856659c3cd67046057fe4b 2024-06-09 2024
#> 6 6659b208c3cd67046057fe31 2024-06-09 2024
#> 7 6659b140c3cd67046057fe2d 2024-06-09 2024
#> 8 6659af29c3cd67046057fe29 2024-06-09 2024
#> 9 6659ae82c3cd67046057fe25 2024-06-09 2024
#> 10 6659ad59c3cd67046057fe21 2024-06-09 2024
#> # ℹ 17,856 more rows