Reputation: 2861
I am using Rank()
to assign a rank value to a dataframe, however I need the rank to be 1 = Highest and not 1 = Lowest.
Upvotes: 20
Views: 50624
Reputation: 24545
Also, order()
can be used with negative sign:
> x = 1:10
> order(-x)
[1] 10 9 8 7 6 5 4 3 2 1
Upvotes: 10
Reputation: 184
While rank(-x)
will certainly work for numeric and logical vectors, it won't work on character vectors, as those cannot be negated. Instead, a solution which work on all types of vectors:
rank(-rank(x))
Upvotes: 3
Reputation: 1
ascending_order=arrange[order(arrange)]
Rank_values=rank(ascending_order)
Upvotes: -1
Reputation: 149
Or you could use :
> x = c(1,2,3,4,5)
> rank(desc(x))
[1] 5 4 3 2 1
Upvotes: 12
Reputation: 12411
If you want to get the rank of x
from the largest to the smallest, do
rank(-x)
Upvotes: 46