Learn R Programming

cwhmisc (version 6.0)

w.median: Weighted median

Description

Compute the weighted median.

Usage

w.median (x,w)

Arguments

x,w
Real, data and weights

See Also

median, quantile

Examples

Run this code
w.median(c(7,1,2,4,10,15),c(1,1/3,1/3,1/3,1,1)) #  7
w.median(c(1,2,4,7,10,15),c(1/3,1/3,1/3,1,1,1)) #  7
w.median(c(7,7/3,10,15)) # 7
     # '1','2','4 of weights='1/3' are replaced by '7/3' (weight=1)
w.median(c(7,1,2,4,10),c(1,1/3,1/3,1/3,1)) #  7
w.median(c(7,1,2,4,10)) #  4
w.median(c(7,1,NA,4,10),c(1,1/3,1/3,1/3,1)) # 7

Run the code above in your browser using DataLab