How to get ranks with no gaps when there are ties among values?

Modified crayola solution but using match instead of merge:

x_unique <- unique(x)
x_ranks <- rank(x_unique)
x_ranks[match(x,x_unique)]

edit

or in a one-liner, as per @hadley ‘s comment:

match(x, sort(unique(x)))

Leave a Comment