10
$\begingroup$
data = {33, 6, 10};
Ordering[data]
(* {2, 3, 1} *)

What I really want is, 3 for 33, as it is the 3rd, if sorted; 1 for 6, as it is the 1st, if sorted; and 2 for 10, as it is the 2nd, if sorted; so I want this returned:

(* {3,1,2} *)

How to do that? I checked the help page for Order and Sort, which is unless.

$\endgroup$
1

1 Answer 1

16
$\begingroup$
Ordering @ Ordering @ data

{3,1,2}

Also:

Statistics`Library`GetDataRankings[data]
Nest[Ordering, data, 2]
Composition[Ordering, Ordering][data]

all give

{3,1,2}

$\endgroup$
2
  • 4
    $\begingroup$ This seemed to easy, which should be an example in the help page! Thanks! $\endgroup$ Dec 6, 2014 at 16:12
  • 1
    $\begingroup$ @ChenStatsYu, i agree... $\endgroup$
    – kglr
    Dec 6, 2014 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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