Skip to contents

weighted.quantile() produces weighted sample quantiles corresponding to the given probabilities.

Usage

weighted.quantile(
  x,
  w = NULL,
  probs = seq(0, 1, 0.25),
  na.rm = FALSE,
  names = TRUE,
  digits = 7L,
  type = 1L,
  ...
)

Arguments

x

a numeric vector whose weighted sample quantiles are wanted.

w

a numeric vector of the sample weights for each value in x.

probs

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

na.rm

logical. If TRUE, any NA and NaNs are removed from x before the quantiles are computed.

names

logical. If TRUE, the result has a "names" attribute.

digits

used only when names is TRUE. The precision to use when formatting the percentages.

type

an integer between 1 and 9 selecting the quantile algorithms. Only 1 is available for the weighted quantile.

...

further arguments passed to stats::quantile() when the weights is not passed.

Value

weighted.quantile() returns weighted sample quantiles corresponding to the given probabilities.

Details

weighted.quantile() is a wrapper function of stats::quantile() for weighted quantiles. For the weighted quantile, only the "type 1" quantile, the inverse of the empirical distribution function, is available.

Examples

stats::quantile(x = 1:10, type = 1L, probs = c(0, .25, .50, .75, 1))
#>   0%  25%  50%  75% 100% 
#>    1    3    5    8   10 
weighted.quantile(x = 1:10, w = 1:10, probs = c(0, .25, .50, .75, 1))
#>   0%  25%  50%  75% 100% 
#>    1    5    7    9   10