Skip to content
Prev 311438 / 398513 Next

I don't know the difference between rank and order

On 21-Nov-2012 02:57:19 li1127217ye wrote:
It is because rank() gives, for each element of x, the position
of that value within the sorted series of all the values in x.
This will not, in general, be the same as the index, within x,
of the value that should be in that position.

Example:

  x1=c(6,5,4,2,3,1)

  x1[rank(x1,ties.method="first")]
  # [1] 1 3 2 5 4 6

  rank(x1,ties.method="first")
  # [1] 6 5 4 2 3 1

So "2" indeed has rank 2, and "3" has rank 3; but what will be
returned by x1[rank(x)] will depend on what is in x[2] and x[3]
(in this case "5" and "4" respectively).

Ted.

-------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at wlandres.net>
Date: 21-Nov-2012  Time: 08:13:23
This message was sent by XFMail