Learn R Programming

DescTools (version 0.99.37)

DenseRank: Dense Ranks and Percent Ranks

Description

DenseRank() computes the rank of a vector x and returns the rank as a number. The ranks are consecutive integers beginning with 1. No ranks are skipped if there are ranks with multiple items. So the largest rank value is the number of unique values of x. Unlike rank gives the ranking within the vector x too, but ties are assigned the same rank, with the next ranking(s) skipped.

PercentRank() takes a vector x and returns the percentile that elements of x correspond to.

Usage

DenseRank(x, na.last = TRUE)

PercentRank(x)

Arguments

x

a numeric, complex, character or logical vector.

na.last

for controlling the treatment of NAs. If TRUE, missing values in the data are put last; if FALSE, they are put first; if NA, they are removed; if "keep" they are kept with rank NA.

Value

A numeric vector of the same length as x with names copied from x (unless na.last = NA, when missing values are removed). The vector is of integer type unless x is a long vector.

See Also

rank, factor, order, sort

Examples

Run this code
# NOT RUN {
(r1 <- rank(x1 <- c(3, 1, 4, 15, 92)))

x2 <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5)
names(x2) <- letters[1:11]
(r2 <- rank(x2))        # ties are averaged
(r2 <- DenseRank(x2))   # ranks are enumerated

PercentRank(x2)
# }

Run the code above in your browser using DataLab