TakeLargest

TakeLargest[data,n]

gives the n largest elements of data, sorted in descending order.

TakeLargest[dataprop,n]

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

TakeLargest[data,n,p]

uses the ordering function p for sorting.

TakeLargest[n]

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

Details and Options

Examples

open allclose all

Basic Examples  (4)

Take the two largest numbers in a list:

Do the same using the operator form of TakeLargest:

Get the three 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:

Take the three largest values in an association:

Scope  (9)

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

Quantities can be given as QuantityArray:

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

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:

Find the three largest elements in a TabularColumn object:

Get the four rows with the largest elements in the first column in a Tabular object:

Ties in the first column are resolved by comparing values in the second column:

Take a list of numeric expressions or infinities:

By default, TakeLargest sorts the elements using NumericalOrder:

Use canonical Order instead:

Take a list of lists of integers:

They are not numeric elements, so they are sorted by default following canonical order:

Use instead lexicographic order, which will sort the list by their respective first elements:

Take a list of complex numbers:

Following reverse NumericalOrder, TakeLargest selects numbers with decreasing real part:

Options  (2)

ExcludedForms  (2)

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

Specify which elements should be excluded:

By default, TakeLargest takes all elements into account when finding the largest ones:

Exclude particular elements:

Exclude elements matching a given pattern:

Applications  (6)

Get the three planets with the largest radii:

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

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:

Find the five densest chemical elements:

Properties & Relations  (6)

TakeLargest[list,n,p] is effectively equivalent to Take[ReverseSort[list,p],n]:

TakeLargest uses NumericalOrder as default ordering function p:

Using canonical order can give different results:

With numerical inputs, the result of TakeLargest is determined by numerical comparisons:

Comparisons of non-numerical elements effectively follow canonical order:

Order is the default ordering function for Sort and ReverseSort:

TakeLargest[data,] operates at the first level of the input data:

If the input has several levels, it is still elements of the first level that will be sorted and extracted:

Unlike Max, TakeLargest does not return values at deeper levels:

When different numerical expressions have the same value, their original order will be preserved:

TakeLargest[list,n,p] is effectively equivalent to MaximalBy[list,Identity,n,p]:

Take a list of five dates in the current year:

Get the two latest of the dates with TakeLargest:

Get the second latest of the dates with RankedMax:

Possible Issues  (2)

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

Use UpTo to get as many elements as possible:

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

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

Text

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

CMS

Wolfram Language. 2015. "TakeLargest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. 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="2025", howpublished="\url{https://reference.wolfram.com/language/ref/TakeLargest.html}", note=[Accessed: 21-January-2025 ]}

BibLaTeX

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