39
$\begingroup$

I am looking to rank data that, in some cases, the larger value has the rank of 1. I am relatively new to R, but I don't see how I can adjust this setting in the rank function.

x <- c(23,45,12,67,34,89)
rank(x)

generates:

[1] 2 4 1 5 3 6

when I want it to be:

[1] 5 3 6 2 4 1

I assume this is very basic, but any help you can provide will be very much appreciated.

$\endgroup$
73
$\begingroup$

You could negate x:

> rank(-x)
[1] 5 3 6 2 4 1
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.