vec_rank  R Documentation 
vec_rank()
computes the sample ranks of a vector. For data frames, ranks
are computed along the rows, using all columns after the first to break
ties.
vec_rank(
x,
...,
ties = c("min", "max", "sequential", "dense"),
incomplete = c("rank", "na"),
direction = "asc",
na_value = "largest",
nan_distinct = FALSE,
chr_proxy_collate = NULL
)
x 
A vector 
... 
These dots are for future extensions and must be empty. 
ties 
Ranking of duplicate values.

incomplete 
Ranking of missing and incomplete observations.

direction 
Direction to sort in.

na_value 
Ordering of missing values.

nan_distinct 
A single logical specifying whether or not 
chr_proxy_collate 
A function generating an alternate representation of character vectors to use for collation, often used for localeaware ordering.
For data frames, Common transformation functions include: 
Unlike base::rank()
, when incomplete = "rank"
all missing values are
given the same rank, rather than an increasing sequence of ranks. When
nan_distinct = FALSE
, NaN
values are given the same rank as NA
,
otherwise they are given a rank that differentiates them from NA
.
Like vec_order_radix()
, ordering is done in the Clocale. This can affect
the ranks of character vectors, especially regarding how uppercase and
lowercase letters are ranked. See the documentation of vec_order_radix()
for more information.
vec_order_radix()
vec_slice()
x < c(5L, 6L, 3L, 3L, 5L, 3L)
vec_rank(x, ties = "min")
vec_rank(x, ties = "max")
# Sequential ranks use an increasing sequence for duplicates
vec_rank(x, ties = "sequential")
# Dense ranks remove gaps between distinct values,
# even if there are duplicates
vec_rank(x, ties = "dense")
y < c(NA, x, NA, NaN)
# Incomplete values match other incomplete values by default, and their
# overall position can be adjusted with `na_value`
vec_rank(y, na_value = "largest")
vec_rank(y, na_value = "smallest")
# NaN can be ranked separately from NA if required
vec_rank(y, nan_distinct = TRUE)
# Rank in descending order. Since missing values are the largest value,
# they are given a rank of `1` when ranking in descending order.
vec_rank(y, direction = "desc", na_value = "largest")
# Give incomplete values a rank of `NA` by setting `incomplete = "na"`
vec_rank(y, incomplete = "na")
# Can also rank data frames, using columns after the first to break ties
z < c(2L, 3L, 4L, 4L, 5L, 2L)
df < data_frame(x = x, z = z)
df
vec_rank(df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.