Wolfram Research

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 with items other than 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 their 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]=

Resource History

Related Resources

License Information