Computes the weighted quantiles of a distribution.

weighted.quantile(x, weights = NULL, probs = seq(0, 1, 0.25),
                  na.rm = FALSE, names = FALSE)

Arguments

x

numeric vector whose sample quantiles are wanted

weights

numeric vector of weights. If NULL (default), uniform weights (i.e. all equal to 1) are used.

probs

numeric vector of probabilities with values in [0,1]

na.rm

logical, indicating whether NA values should be silently removed before the computation proceeds. Default is FALSE.

names

logical. if TRUE, the result has a names attribute. Default is FALSE.

Value

A numeric vector of the same length as probs argument.

Note

This function is taken from https://stackoverflow.com/questions/2748725/is-there-a-weighted-median-function

See also

Examples

data(Movies)
weighted.quantile(Movies$Critics, weights = rep(c(.8,1.2), 500), names = TRUE)
#>   0%  25%  50%  75% 100% 
#> 1.00 2.25 3.00 3.50 5.00