Learn R Programming

robcp (version 0.3.8)

weightedMedian: Weighted Median

Description

Computes the weighted median of a numeric vector.

Usage

weightedMedian(x, w)

Value

Weighted median of x with respect to w.

Arguments

x

Numeric vector.

w

Integer vector of weights.

Details

Here, the median of an even length \(n\) of \(x\) is defined as \(x_{(n/2 + 1)}\) if \(x_{(i)}\) is the \(i\)-th largest element in \(x\), i.e. the larger value is taken.

Examples

Run this code
x <- c(1, 4, 9)
w <- c(5, 1, 1)
weightedMedian(x, w)

Run the code above in your browser using DataLab