When there are ties in the original data, is there a way to create a ranking without gaps in the ranks (consecutive, integer rank values)? Suppose:
x <-
Modified crayola solution but using match instead of merge:
match
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)))