TakeLargest

TakeLargest[list,n]

gives the n numerically largest elements in list, sorted in descending order.

TakeLargest[listprop,n]

gives the property prop for the n largest elements in list.

TakeLargest[n]

represents an operator form of TakeLargest that can be applied to an expression.

Details and Options

Examples

open allclose all

Basic Examples  (6)

Take the two largest numbers in a list:

Do the same using the operator form of TakeLargest:

Take the two largest values in an association:

Get the two largest quantities in a list of Quantity objects:

Quantities can be present in multiple units:

Get the two latest dates in a list of DateObject constructs:

By default, Missing[] and several other symbolic expressions are excluded from the results:

Take the 4 largest numbers, or as many as are available if fewer:

Scope  (4)

Get the two largest elements in a list:

Get the positions of the two largest elements in a list:

Get the two largest elements in a list along with their positions:

Get the two largest elements in a list with their positions given first:

Get associations containing the element and position of the two largest elements in a list:

Get the three planets with the largest radii:

Get the release dates of the five most recent James Bond movies:

Options  (1)

ExcludedForms  (1)

The option ExcludedForms->list specifies that elements matching any of the forms in list should be dropped before the elements are compared:

The default value ExcludedForms->Automatic excludes some common non-numeric expressions, but leaves most symbolic expressions:

Applications  (3)

Find the South American countries with the highest life expectancy for their inhabitants:

Find the codons (groups of three consecutive nucleotides) with the highest relative frequencies in the list of nucleotides of a gene:

Find the noble gases with the highest boiling point and density:

Possible Issues  (2)

If fewer than the requested number of elements are present, TakeLargest will not evaluate:

If the elements are not comparable, TakeLargest will not evaluate:

Neat Examples  (1)

Take the five densest chemical elements:

Wolfram Research (2015), TakeLargest, Wolfram Language function, https://reference.wolfram.com/language/ref/TakeLargest.html (updated 2019).

Text

Wolfram Research (2015), TakeLargest, Wolfram Language function, https://reference.wolfram.com/language/ref/TakeLargest.html (updated 2019).

CMS

Wolfram Language. 2015. "TakeLargest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2019. https://reference.wolfram.com/language/ref/TakeLargest.html.

APA

Wolfram Language. (2015). TakeLargest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TakeLargest.html

BibTeX

@misc{reference.wolfram_2024_takelargest, author="Wolfram Research", title="{TakeLargest}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/TakeLargest.html}", note=[Accessed: 22-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_takelargest, organization={Wolfram Research}, title={TakeLargest}, year={2019}, url={https://reference.wolfram.com/language/ref/TakeLargest.html}, note=[Accessed: 22-November-2024 ]}