weighted.median: Calculate the lower weighted median of a specified vector.

View source: R/weighted.median.R

weighted.medianR Documentation

Calculate the lower weighted median of a specified vector.

Description

Compute the lower weighted median of a specified vector. The weighted median is considered to be the value where the sum of probabilities of order values is equals to half of the total sum of all probabilities.

Usage

weighted.median(v, weights)

Arguments

v

a vector of double containing the values used for the calculation.

weights

a vector of double containing the weight for each value of the v vector.

Value

a double which is the weighted median of the vector.

Author(s)

Alexander Krasnitz, Guoli Sun

Examples


## Vector of values
values <- c(0.06363411, 0.04342896, 0.07207384, 0.07319237, 0.07273546,
    0.01463932, 0.02136043, 0.01967027)

## Vector of weight associated to each value    
weight <- c(1, 1, 1, 1, 0, 0, 0, 0)

## Calculation of the weighted median
CNprep:::weighted.median(v=values, weights=weight)


KrasnitzLab/CNprep documentation built on May 28, 2022, 8:32 p.m.