View source: R/dep_quantiles.R
dep_quantiles | R Documentation |
This helper function can be used to return quantiles of a deprivation index (or any other continuous distribution). This is useful for constructing independent variables for statistical analysis. The function supports splitting a distribution at the median (2 quantiles) through deciles (10 quantiles) if character labels are desired.
dep_quantiles(.data, source_var, new_var, n = 4L, return = "label")
.data |
A tibble containing the data to be used for calculating quantiles. |
source_var |
Required; the quoted or unquoted source variable to be divided into quantiles. |
new_var |
Required; the quoted or unquoted name of the new variable to be created containing the quantile values. |
n |
Required integer scalar; the number of quantiles to divide the source
variable into. Defaults to |
return |
Required character scalar; one of either |
A copy of .data
with a new variable containing the requested
quantile.
## load sample data
ndi_m <- dep_sample_data(index = "ndi_m")
## calculate NDI with sample data
ndi_m <- dep_calc_index(ndi_m, geography = "county", index = "ndi_m", year = 2022,
return_percentiles = TRUE)
## calculate quantiles, return label
ndi_m <- dep_quantiles(ndi_m, source_var = NDI_M, new_var = ndi_m_quartiles_l)
unique(sort(ndi_m$ndi_m_quartiles_l))
## calculate quantiles, return label
ndi_m <- dep_quantiles(ndi_m, source_var = NDI_M, new_var = ndi_m_quartiles_l6,
n = 6L)
unique(sort(ndi_m$ndi_m_quartiles_l6))
## calculate quantiles, return factor
ndi_m <- dep_quantiles(ndi_m, source_var = NDI_M, new_var = ndi_m_quartiles_f,
return = "factor")
levels(ndi_m$ndi_m_quartiles_f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.