Calculates weighted median based on weighted_quantile().

weighted_median(x, w = NULL, ...)

Arguments

x

Numeric vector.

w

Optional vector of non-negative case weights.

...

Further arguments passed to weighted_quantile().

Value

A length-one numeric vector.

Examples

n <- 21
x <- seq_len(n)
quantile(x, probs = 0.5)
#> 50% 
#>  11 
weighted_median(x, w = rep(1, n))
#> [1] 11
weighted_median(x, w = x)
#> [1] 15
quantile(rep(x, x), probs = 0.5)
#> 50% 
#>  15