View source: R/weighted_percentiles.R
compute_weighted_percentiles | R Documentation |
This function computes weighted percentiles of a numeric vector, or the share of total value within specified percentile intervals.
compute_weighted_percentiles(
var,
wgt = NULL,
probs = seq(0, 1, 0.25),
na.rm = TRUE,
share = FALSE,
type = c("type_4", "type_2")
)
var |
A numeric vector of values (e.g., .x$dhi, .x$pi11). |
wgt |
A numeric vector of weights (e.g., .x$hpopwgt, .x$pwgt). Must be the same length as |
probs |
A numeric vector of probabilities between 0 and 1 indicating which percentiles to compute. Default is |
na.rm |
Logical; if |
share |
Logical; if |
type |
A character string indicating which percentile definition to use. Either |
A named numeric vector. If share = FALSE
, returns weighted percentiles with names corresponding to the percentiles (e.g., "25%"). If share = TRUE
, returns the share of the total value in each percentile range (e.g., "0-25%").
## Not run:
data <- lissyrtools::lissyuse(data = "es22", vars = c("dhi", "age"))
compute_weighted_percentiles(data$es22$dhi, data$es22$ppopwgt)
compute_weighted_percentiles(data$es22$dhi, data$es22$ppopwgt, probs = c(0.03, 0.72, 0.48, .01))
compute_weighted_percentiles(data$es22$dhi, data$es22$ppopwgt, probs = c(0.03, 0.72, 0.48, .01), share = TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.