PositionLargest

The position of the largest elements in a list

Definition(MoreInfoOpenerButtonTemplate[Definition, Define your function using the name above. All definitions, including dependencies, will be included in the resource function when it is generated. Additional cells can be added and definitions can be given for multiple input cases.

This section should be evaluated before evaluating creating the Examples section below.])

PositionLargest[list_List]/;AllTrue[list,NumericQ]:=First[FirstPosition[list,Max[list]]]

PositionLargest[list_List,n:(_Integer|HoldPattern[UpTo][_Integer])]/;AllTrue[list,NumericQ]:=Take[Flatten[Position[list,#]&/@DeleteDuplicates[TakeLargest[list,n]]],n]

Documentation

Usage(MoreInfoOpenerButtonTemplate[Usage, Document every accepted input usage case. Use Enter to create new cases as needed.

Each usage should contain a brief explanation saying what the function does for the given input structure.

See existing documentation pages for examples.])

Details & Options(MoreInfoOpenerButtonTemplate[Details & Options, Give a detailed explanation of how the function is used. Add multiple cells including tables and hyperlinks as needed. Typical information includes: acceptable inputs, result formats, options specifications, and background information.])

All elements of list must be numeric.

PositionLargest[list,UpTo[n]] is supported.

Examples(MoreInfoOpenerButtonTemplate[Examples, Demonstrate how to use the function. Examples should start with the most basic use case. Each example should be described using text cells. Use "Subsection" and "Subsubsection" cells to group examples as needed.

See existing documentation pages for examples.])

Basic Examples

Find the position of the largest element in a list:

PositionLargest[{100,200,100,200,50}]

Specify a number of positions to get in a list:

PositionLargest[{100,200,100,200,50},1]

Find the positions of the three largest elements in order:

PositionLargest[{100,200,100,200,50},3]

Scope

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

moons=Values/@ResourceData["Sample Data: Solar System Planets and Moons"][All,"Moons",QuantityMagnitude/*DeleteMissing,"Mass"]

PositionLargest[#,UpTo[2]]&/@moons

Source & Additional Information

Contributed By(MoreInfoOpenerButtonTemplate[Contributed By, Name of the person, people or organization that should be publicly credited with contributing the function.])

Stephen Wolfram

Keywords(MoreInfoOpenerButtonTemplate[Keywords, List relevant terms that should be used to include this resource in search results.])

Position

Largest

Find

Locate

Max

Index

Related Symbols(MoreInfoOpenerButtonTemplate[Related Symbols, List related Wolfram Language symbols. Include up to twenty documented, system-level symbols.])

Position

FirstPosition

PositionIndex

TakeLargest

TakeLargestBy

Related Resource Objects(MoreInfoOpenerButtonTemplate[Related Resource Objects, Names of published resource objects from any Wolfram repository that are related to this resource.])

PositionLargestBy

Source/Reference Citation(MoreInfoOpenerButtonTemplate[Source/Reference Citation, Citation for original source of the function or its components. For example, original publication of an algorithm or public code repository.])

Links(MoreInfoOpenerButtonTemplate[Links, URLs or hyperlinks for external information related to the function.])

Tests(MoreInfoOpenerButtonTemplate[Tests, Optional list of tests that can be used to verify that the function is working properly in any environment.
Tests can be specified as Input/Output cell pairs or as literal VerificationTest expressions if you need to specify options.])

PositionLargest[Range[100]]

PositionLargest[{100,200,100,200,50}]

PositionLargest[{100,200,100,200,50},1]

PositionLargest[{100,200,100,200,50},3]

Author Notes

Submission Notes(MoreInfoOpenerButtonTemplate[Submission Notes, Enter any additional information that you would like to communicate to the reviewer here. This section will not be included in the published resource.])

Should have error cases when there is no way to compute a definite Max in the list