Skip to contents

Computes the weighted percentile of a numeric vector given weights. Use for summarizing survey or model outputs at arbitrary percentiles.

Usage

weighted.percentile(x, w, p)

Arguments

x

numeric vector. Values to summarize.

w

numeric vector. Weights for each value.

p

numeric(1). Target percentile (0-1).

Value

numeric(1). Weighted percentile value.

Details

  • Orders values and weights.

  • Computes cumulative probability and finds closest to target percentile.

  • Returns weighted percentile value.

Settings

None.

See also

weighted.median

Other utility functions: archive_file(), clip.vector(), fillna(), weighted.median()

Examples

weighted.percentile(c(1, 2, 3), c(0.2, 0.5, 0.3), 0.5)
#> [1] 2