ntile()
is a sort of very rough rank, which breaks the input vector into
n
buckets. If length(x)
is not an integer multiple of n
, the size of
the buckets will differ by up to one, with larger buckets coming first.
Unlike other ranking functions, ntile()
ignores ties: it will create
evenly sized buckets even if the same value of x
ends up in different
buckets.
Usage
ntile(x = row_number(), n)
Arguments
- x
A vector to rank
By default, the smallest values will get the smallest ranks. Use
desc()
to reverse the direction so the largest values get the smallest ranks.Missing values will be given rank
NA
. Usecoalesce(x, Inf)
orcoalesce(x, -Inf)
if you want to treat them as the largest or smallest values respectively.To rank by multiple columns at once, supply a data frame.
- n
Number of groups to bucket into
See also
Other ranking functions:
percent_rank()
,
row_number()