wolfram mathematica - equal value = equal rank -


i rank elements of list such elements have same value same rank:

list = {1, 2, 3, 4, 4, 5} 

desired output:

ranks = {5, 4, 3, 2, 2, 1} 

ordering[] want assigns different ranks 2 instances of 4 in list.

i not sure cover have in mind, following code give desired output. presupposes smallest value highest rank, , should work numerical values or long ok standard sorting order of mathematica. local variable dv shortname "distinct values".

  fromlisttoranks[k_list]:= module[ {dv=reverse[union[k]]},     k /. thread[dv -> range[length[dv]]] ]     fromlisttoranks[list]    {5,4,3,2,2,1} 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -