Function Repository Resource:

Ranking

Source Notebook

Find the rank of each of the items in a list

Contributed by: Sander Huisman

ResourceFunction["Ranking"][list]

finds the rank of each of the items in the list list.

Examples

Basic Examples (1) 

Find the rank of each of the numbers:

In[1]:=
ResourceFunction["Ranking"][{14, 312, 0, 3, 1}]
Out[1]=

Scope (2) 

Ranking works with lists whose elements are not numbers:

In[2]:=
a = {14, "string", 312, 0, 3, x};
ResourceFunction["Ranking"][a]
Out[2]=

Ranking follows the conventions of Sort:

In[3]:=
a[[Ordering[a]]] == Sort[a]
Out[3]=

Applications (1) 

Color some data by its ranking:

In[4]:=
a = {14, 312, 0, 3, 1, 1000, -4};
r = ResourceFunction["Ranking"][a];
colors = Blend[{Red, Green}, #] & /@ Rescale[r];
MapThread[Style, {a, colors}]
Out[4]=

Properties and Relations (1) 

Ranking is the Ordering of the Ordering:

In[5]:=
a = {14, 312, 0, 3, 1};
{ResourceFunction["Ranking"][a], Ordering[Ordering[a]]}
Out[5]=

Publisher

SHuisman

Version History

  • 1.0.0 – 17 August 2021

Related Resources

License Information