Learn R Programming

robsurvey (version 0.1.0)

weighted_median: Weighted median with weighted interpolation

Description

weighted_median computes a weighted median where the exact location corresponds exactly to a cumulative weight of 0.5. This yields a symmetric median.

Usage

weighted_median(x, w, na.rm = FALSE)

Arguments

x

a numeric vector whose weighted sample median is wanted

w

a numeric vector of weights

na.rm

a logical value indicating whether NA values should be stripped before the computation proceeds.

Value

weighted sample median

Details

Note that the weighted_median function delivers a symmetric median while the weighted_quantile function with probability 0.5 delivers the lower median. Hence, the results of these two functions will generally differ.

See Also

weighted_quantile

Examples

Run this code
# NOT RUN {
x <- c(0.1, 0.35, 0.05, 0.1, 0.15, 0.05, 0.2)
weighted_median(x, x)
# }

Run the code above in your browser using DataLab