Use of rank() & order() functions in R dplyr package with example

r
dplyr

#1

Hi All,

Could someone explain Use of rank() & order() functions in R “dplyr” package with example .I am a newbie & confused .

Regards


#2

Got the concept clear guys .Thanks .


#3

Rank returns a vector with the “rank” of each value.

Order returns the indices that would put the initial vector x in order.

Example Below :

x <- sample(1:50, 10)

x
[1] 13 4 35 15 5 2 29 19 27 16

rank(x)
[1] 4 2 10 5 3 1 9 7 8 6

order(x)
[1] 6 2 5 1 4 10 8 9 7 3