Join a percent change in variable relative to a reference year
Source:R/pivot_ipumsr.R
join_nhgis_percent_change.Rd
join_nhgis_percent_change()
joins a percent change column relative to a
reference year. Optionally join a rank from the reference year using
dplyr::ntile()
.
Usage
join_nhgis_percent_change(
data,
reference_year = NULL,
value_col = "value",
reference_prefix = "reference_",
variable_col = "variable",
year_col = "YEAR",
rank_col = "rank",
rank = NULL,
rank_n = NULL,
rank_by = NULL,
...,
perc_prefix = "perc_change_",
digits = 2
)
Arguments
- reference_year
Reference year to use when calculating a percent change column.
- rank, rank_n
Passed to
x
andn
arguments ofdplyr::ntile()
to join a reference rank value.- rank_by
Used as
.by
argument ofdplyr::mutate()
ifrank_n
is notNULL
.