53

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.

Btibert3
  • 1,334
  • 2
  • 15
  • 24

1 Answers1

100

You could negate x:

> rank(-x)
[1] 5 3 6 2 4 1
Gavin Simpson
  • 47,626