get_rank: Wrapper around base rank allowing for dense rank output

View source: R/get_rank.R

get_rankR Documentation

Wrapper around base rank allowing for dense rank output

Description

Internally base::rank is used (hence, same parameters) but amended by the option ties.method = "dense" based on the implementaion of dense_rank in dplyr package.

Usage

get_rank(x, decreasing = FALSE, na.last = TRUE, ties.method = "average")

Arguments

x

...

decreasing

By default set to FALSE to comply with the logic of base::rank. Set to TRUE to rank the highest number in x with 1. This option is currently only implemented for dense ranking.

na.last

...

ties.method

... amended by "dense".

Value

...

Examples


x <- sample(1:1000, 100)
all(base::rank(x) == get_rank(x))
#TRUE

x <- c(11,11,12,13)
base::rank(x)
#[1] 1.5 1.5 3.0 4.0
get_rank(x, ties.method = "dense", decreasing = FALSE)
#[1] 1 1 2 3
get_rank(x, ties.method = "dense", decreasing = TRUE)
#[1] 3 3 2 1

manuelbickel/textility documentation built on Nov. 25, 2022, 9:07 p.m.