Calculate percentiles for a given variable in a data frame. This is the method used to calculate ranked percentiles for SVI.

dep_percentiles(.data, source_var, new_var)

Arguments

.data

A tibble containing the data to be used for calculating percentiles.

source_var

Required; the quoted or unquoted source variable to be divided into percentiles.

new_var

Required; the quoted or unquoted name of the new variable to be created containing the quantile values.

Value

An updated tibble with the percentiles added as a new column or with replaced values in the source column.

Examples

## load sample data
ndi_m <- dep_sample_data(index = "ndi_m")

# calculate percentiles for population 25 years and older
ndi_m <- dep_percentiles(ndi_m, source_var = B06009_001E,
    new_var = pop25_percentile)

# preview the new data
ndi_m[names(ndi_m) %in% c("GEOID", "B06009_001E", "pop25_percentile")]
#> # A tibble: 115 × 3
#>    GEOID B06009_001E pop25_percentile
#>    <chr>       <dbl>            <dbl>
#>  1 29001       13868           0.535 
#>  2 29003       12659           0.5   
#>  3 29005        3857           0.0702
#>  4 29007       17336           0.640 
#>  5 29009       24415           0.719 
#>  6 29011        7997           0.298 
#>  7 29013       11069           0.439 
#>  8 29015       15146           0.570 
#>  9 29017        7616           0.289 
#> 10 29019      111010           0.939 
#> # ℹ 105 more rows