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,889 × 3
#> id date week
#> <chr> <date> <int>
#> 1 670cd145c3cd67046058015c 2024-06-09 23
#> 2 66fff490c3cd670460580111 2024-09-22 38
#> 3 66ffdfe3c3cd6704605800fc 2024-09-22 38
#> 4 66f686cfc3cd6704605800a0 2024-09-22 38
#> 5 66f68317c3cd67046058009c 2024-09-22 38
#> 6 66d6da9cc3cd670460580053 2024-09-22 38
#> 7 66cde603c3cd67046057fff5 2024-09-22 38
#> 8 66c46f86c3cd67046057ff53 2024-09-22 38
#> 9 66c46cf6c3cd67046057ff4f 2024-09-22 38
#> 10 66c46c3ac3cd67046057ff4b 2024-09-22 38
#> # ℹ 17,879 more rows
rdb::rfrnds(quiet = TRUE) |>
rdb::add_period("year") |>
dplyr::select(id, date, year)
#> # A tibble: 17,889 × 3
#> id date year
#> <chr> <date> <int>
#> 1 670cd145c3cd67046058015c 2024-06-09 2024
#> 2 66fff490c3cd670460580111 2024-09-22 2024
#> 3 66ffdfe3c3cd6704605800fc 2024-09-22 2024
#> 4 66f686cfc3cd6704605800a0 2024-09-22 2024
#> 5 66f68317c3cd67046058009c 2024-09-22 2024
#> 6 66d6da9cc3cd670460580053 2024-09-22 2024
#> 7 66cde603c3cd67046057fff5 2024-09-22 2024
#> 8 66c46f86c3cd67046057ff53 2024-09-22 2024
#> 9 66c46cf6c3cd67046057ff4f 2024-09-22 2024
#> 10 66c46c3ac3cd67046057ff4b 2024-09-22 2024
#> # ℹ 17,879 more rows