Learn R Programming

wdm (version 0.2.6)

rank_wtd: Computing weighted ranks

Description

The weighted rank of \(X_i\) among \(X_1, \dots, X_n\) with weights \(w_1, \dots, w_n\) is defined as $$\frac 1 n \sum_{j = 1}^n w_i 1[X_j \le X_i].$$

Usage

rank_wtd(x, weights = numeric(), ties_method = "average")

Value

a vector of ranks.

Arguments

x

a numeric vector.

weights

a vector of weights (same length as x).

ties_method

Indicates how to treat ties; same as in R, see https://stat.ethz.ch/R-manual/R-devel/library/base/html/rank.html.

Examples

Run this code
x <- rnorm(100)
w <- rexp(100)
rank(x)
rank_wtd(x, w)

Run the code above in your browser using DataLab