# Finding column-wise ranks of values in a multidimensional list

I often have to find ranks of values in a list. However, Mathematica does not have built-in functions for that, or may be I'm just not aware of them. I can easily find ranks of a row/column vector. For example, if I have

list1 = RandomInteger[{1, 10}, 10] ;


then Ordering[Ordering[list1]] gives me its rank. I have also written a following function that does my job.

 Rankme[list_] := Module[{rank},
rank = ConstantArray[0, Length[list]];
rank[[Ordering[list]]] = Range[1, Length[list]] ;
rank
]


Rankme[list1] gives me ranks of values in the list1 . However, I am trying to find column-wise ranks of a list that has more than one column. For example, I have

list2 = RandomInteger[{1, 10}, {10, 5}];


I want to find column-wise ranks of values in the list2. How can I do this?

rrF = Ordering@Ordering@# &;
crF = Transpose[rrF /@ Transpose[#]] &;

mat = RandomInteger[{1, 10}, {10, 5}];
Row[MatrixForm /@ {mat, crF@mat}] Update: Using the function colMap suggested by @Mr.Wizard in the comments

colMap[f_][m_?MatrixQ] := (f /@ (m\[Transpose]))\[Transpose]
(* or Transpose[fn /@ Transpose[m]] *)

colMap[rrF][mat] // MatrixForm


gives same output as crF@mat above.

• Thank you kguler. May be I owe you a couple of cups of coffee. – ramesh Feb 10 '15 at 22:08
• incidentally consider a reusable function colMap[fn_][m_?MatrixQ] := (fn /@ (m\[Transpose]))\[Transpose] (+1) – Mr.Wizard Feb 10 '15 at 22:08
• ramesh, my pleasure. One cup -quad espresso- would be fine:) – kglr Feb 10 '15 at 22:12
• @Mr.Wizard, great idea, thank you. Will update with the colMap function. – kglr Feb 10 '15 at 22:13
Ordering /@ Transpose[RandomVariate[UniformDistribution[{10}], {3, 4}]]

• Thank you for your quick response. It was easy. – ramesh Feb 10 '15 at 22:01
• If it doesn't give you what you want, please explain why. – David G. Stork Feb 10 '15 at 22:35