Calculates empirical sample quantiles with optional weights, for given
probabilities. Like in quantile()
, the smallest observation corresponds to
a probability of 0 and the largest to a probability of 1.
Interpolation between discrete values is done when type=7
, as in quantile()
.
Use type=1
to only generate quantile values from the raw input samples.
Usage
wquantile(
x,
probs = seq(0, 1, 0.25),
na.rm = FALSE,
type = 7,
weights = NULL,
...
)
Arguments
- x
numeric vector whose sample quantiles are wanted.
NA
andNaN
values are not allowed in numeric vectors unlessna.rm
is TRUE.- probs
numeric vector of probabilities with values in \([0,1]\).
- na.rm
logical; if true, any
NA
andNaN
's are removed fromx
before the quantiles are computed.- type
numeric, 1 for no interpolation, or 7, for interpolated quantiles. Default is 7.
- weights
numeric vector of non-negative weights, the same length as
x
, orNULL
. The weights are normalised to sum to 1. IfNULL
, thenwquantile(x)
behaves the same asquantile(x)
, with equal weight for each sample value.- ...
Additional arguments, currently ignored
Examples
# Some random numbers
x <- rnorm(100)
# Plain quantiles:
quantile(x)
#> 0% 25% 50% 75% 100%
#> -2.1775760 -0.4950209 0.1309871 0.8588734 2.1587566
# Larger values given larger weight, on average shifting the quantiles upward:
wquantile(x, weights = sort(runif(length(x))))
#> [1] -2.1775760 -0.4175936 0.2000932 1.0427150 2.1587566