ntile {dplyr} | R Documentation |
n
groupsntile()
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.
ntile(x = row_number(), n)
x |
A vector to rank By default, the smallest values will get the smallest ranks. Use Missing values will be given rank To rank by multiple columns at once, supply a data frame. |
n |
Number of groups to bucket into |
Other ranking functions:
percent_rank()
,
row_number()
x <- c(5, 1, 3, 2, 2, NA)
ntile(x, 2)
ntile(x, 4)
# If the bucket sizes are uneven, the larger buckets come first
ntile(1:8, 3)
# Ties are ignored
ntile(rep(1, 8), 3)