-1

I have a simple Matrix and want to have the ranks for each entry.

     [,1] [,2]
[1,]  5    8
[2,]  8    5

When I use rank() with ties.method=min it has a jump after the tie:

rankMatrix[] <- rank(-Matrix, ties.method="min")

it gives me the following:

     [,1] [,2]
[1,]  3    1
[2,]  1    3

My problem is that I do not want to have a jump in rank after the tie, i.e.:

     [,1] [,2]
[1,]  2    1
[2,]  1    2

Is there any way to achieve this sort of ranking?

Thanks a lot in advance!

Malte Dvl
  • 19
  • 2

1 Answers1

1

We could do with dense_rank

library(dplyr)
m1[] <- dense_rank(-m1)
m1
#      [,1] [,2]
#[1,]    2    1
#[2,]    1    2
akrun
  • 874,273
  • 37
  • 540
  • 662