Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Get the position of the largest elements in a list
| 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. | 
Find a position of the largest value in a list:
| In[1]:= | ![ResourceFunction["PositionLargest"][{100, 200, 100, 200, 50}]](https://www.wolframcloud.com/obj/resourcesystem/images/343/34383e37-f622-4870-90b1-d985cffb070d/17330ab2771957c3.png) | 
| Out[1]= |  | 
Specify the number of positions to find:
| In[2]:= | ![ResourceFunction["PositionLargest"][{100, 200, 100, 200, 50}, 1]](https://www.wolframcloud.com/obj/resourcesystem/images/343/34383e37-f622-4870-90b1-d985cffb070d/595a17b90ecb7094.png) | 
| Out[2]= |  | 
Get a list of positions for the three largest values:
| In[3]:= | ![ResourceFunction["PositionLargest"][{100, 200, 100, 200, 50}, 3]](https://www.wolframcloud.com/obj/resourcesystem/images/343/34383e37-f622-4870-90b1-d985cffb070d/28483a0097983831.png) | 
| Out[3]= |  | 
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"]](https://www.wolframcloud.com/obj/resourcesystem/images/343/34383e37-f622-4870-90b1-d985cffb070d/0d98b2c89c567d9a.png) | 
| Out[4]= |  | 
| In[5]:= | ![ResourceFunction["PositionLargest"][#, UpTo[2]] & /@ moons](https://www.wolframcloud.com/obj/resourcesystem/images/343/34383e37-f622-4870-90b1-d985cffb070d/2209296c49aba03e.png) | 
| Out[5]= |  | 
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License