As of Version 13.2, PositionLargest is a built-in symbol.

Function Repository Resource:

PositionLargest

Source Notebook

Get the position of the largest elements in a list

Contributed by: Bob Sandheinrich

ResourceFunction["PositionLargest"][list]

gives the position of the first element that has the largest value in list.

ResourceFunction["PositionLargest"][list,n]

gives the positions of the first n largest values.

Details and Options

All elements of list must be numeric.
UpTo is supported.

Examples

Basic Examples (2) 

Find a position of the largest value in a list:

In[1]:=
ResourceFunction["PositionLargest"][{100, 200, 100, 200, 50}]
Out[1]=

Specify the number of positions to find:

In[2]:=
ResourceFunction["PositionLargest"][{100, 200, 100, 200, 50}, 1]
Out[2]=

Get a list of positions for the three largest values:

In[3]:=
ResourceFunction["PositionLargest"][{100, 200, 100, 200, 50}, 3]
Out[3]=

Scope (1) 

Use UpTo to find the position of the two largest moons orbiting each planet:

In[4]:=
moons = Values /@ ResourceData["Sample Data: Solar System Planets and Moons"][All, "Moons", QuantityMagnitude/*DeleteMissing, "Mass"]
Out[4]=
In[5]:=
ResourceFunction["PositionLargest"][#, UpTo[2]] & /@ moons
Out[5]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 11 October 2018

License Information