TakeLargest
✖
TakeLargest
Details and Options

- TakeLargest gives the largest elements in the first level of the input data. »
- By default, TakeLargest uses NumericalOrder to sort numeric expressions, Quantity objects and DateObject expressions. For other types of objects, TakeLargest sorts by canonical Order.
- In TakeLargest[data,…] the data can have the following forms:
-
{e1,e2,…} list of values, including numbers, quantities, dates, ... » » » Association[…] association of values » QuantityArray[…] quantity array or other structured array » Tabular[…] type-consistent tabular data » TabularColumn[…] type-consistent column data » Dataset[…] general hierarchical data » - TakeLargest[assoc,n] gives an association of length n by taking the n largest values in assoc, preserving their keys.
- In TakeLargest[dataprop,n], possible forms for prop include:
-
"Element" gives each element itself » "Index" gives the index for each element » {prop1,prop2,…} a list of multiple forms » All gives an association with element and index » - TakeLargest[data,UpTo[n]] takes n largest elements, or as many as are available. »
- TakeLargest[n][data] is equivalent to TakeLargest[data,n].
- TakeLargest has option ExcludedForms. With the default setting ExcludedForms->Automatic, TakeLargest drops elements that are None, Null or Indeterminate or have head Missing. »
- The setting ExcludedForms->{patt1,patt2,…} specifies that expressions matching any of the patti should be excluded from results generated by TakeLargest. »
Examples
open allclose allBasic Examples (4)Summary of the most common use cases
Take the two largest numbers in a list:

https://wolfram.com/xid/0gfriki0zkdy-xh63mx

Do the same using the operator form of TakeLargest:

https://wolfram.com/xid/0gfriki0zkdy-cvc29l


https://wolfram.com/xid/0gfriki0zkdy-v32v7i

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

https://wolfram.com/xid/0gfriki0zkdy-knst82

Quantities can be present in multiple units:

https://wolfram.com/xid/0gfriki0zkdy-w0fcsz

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

https://wolfram.com/xid/0gfriki0zkdy-3oy020

Take the three largest values in an association:

https://wolfram.com/xid/0gfriki0zkdy-jgfph4

Scope (9)Survey of the scope of standard use cases
Take the four largest numbers, or as many as are available if fewer:

https://wolfram.com/xid/0gfriki0zkdy-0pcpdc

Quantities can be given as QuantityArray:

https://wolfram.com/xid/0gfriki0zkdy-yh9tlv


https://wolfram.com/xid/0gfriki0zkdy-2gyewy

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

https://wolfram.com/xid/0gfriki0zkdy-c91uu4

Get the two largest elements in a list:

https://wolfram.com/xid/0gfriki0zkdy-2y7vx2

https://wolfram.com/xid/0gfriki0zkdy-5yfcey

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

https://wolfram.com/xid/0gfriki0zkdy-cr2dko

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

https://wolfram.com/xid/0gfriki0zkdy-i70n6a

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

https://wolfram.com/xid/0gfriki0zkdy-dw04qo

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

https://wolfram.com/xid/0gfriki0zkdy-21mfoi

Find the three largest elements in a TabularColumn object:

https://wolfram.com/xid/0gfriki0zkdy-vbz7o4


https://wolfram.com/xid/0gfriki0zkdy-y5poc


https://wolfram.com/xid/0gfriki0zkdy-q3yz2b

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

https://wolfram.com/xid/0gfriki0zkdy-f1trbx

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

https://wolfram.com/xid/0gfriki0zkdy-lwe66f


https://wolfram.com/xid/0gfriki0zkdy-u2slio

Take a list of numeric expressions or infinities:

https://wolfram.com/xid/0gfriki0zkdy-t47mqp
By default, TakeLargest sorts the elements using NumericalOrder:

https://wolfram.com/xid/0gfriki0zkdy-nuornw


https://wolfram.com/xid/0gfriki0zkdy-pu412u

Use canonical Order instead:

https://wolfram.com/xid/0gfriki0zkdy-g87qos


https://wolfram.com/xid/0gfriki0zkdy-i8oy5z

Take a list of lists of integers:

https://wolfram.com/xid/0gfriki0zkdy-88r43g
They are not numeric elements, so they are sorted by default following canonical order:

https://wolfram.com/xid/0gfriki0zkdy-s62hau


https://wolfram.com/xid/0gfriki0zkdy-k7u6vx

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

https://wolfram.com/xid/0gfriki0zkdy-780eu2


https://wolfram.com/xid/0gfriki0zkdy-iba2xt

Take a list of complex numbers:

https://wolfram.com/xid/0gfriki0zkdy-eulo7

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

https://wolfram.com/xid/0gfriki0zkdy-y6axzo


https://wolfram.com/xid/0gfriki0zkdy-n719vd

Options (2)Common values & functionality for each option
ExcludedForms (2)
By default, Missing[] and several other symbolic expressions are excluded from the results:

https://wolfram.com/xid/0gfriki0zkdy-3g7u71

Specify which elements should be excluded:

https://wolfram.com/xid/0gfriki0zkdy-lkv7y1

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

https://wolfram.com/xid/0gfriki0zkdy-t5ajgx


https://wolfram.com/xid/0gfriki0zkdy-sj9u1o

Exclude elements matching a given pattern:

https://wolfram.com/xid/0gfriki0zkdy-bpk7xd

Applications (6)Sample problems that can be solved with this function
Get the three planets with the largest radii:

https://wolfram.com/xid/0gfriki0zkdy-0pyx9e

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

https://wolfram.com/xid/0gfriki0zkdy-8g10g5

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

https://wolfram.com/xid/0gfriki0zkdy-dxxfrk

https://wolfram.com/xid/0gfriki0zkdy-c5onpe

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

https://wolfram.com/xid/0gfriki0zkdy-mspsp

https://wolfram.com/xid/0gfriki0zkdy-jv7ahy

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

https://wolfram.com/xid/0gfriki0zkdy-bbke0c


https://wolfram.com/xid/0gfriki0zkdy-jr3j1b


https://wolfram.com/xid/0gfriki0zkdy-egxzya

Find the five densest chemical elements:

https://wolfram.com/xid/0gfriki0zkdy-cmwew7

Properties & Relations (6)Properties of the function, and connections to other functions
TakeLargest[list,n,p] is effectively equivalent to Take[ReverseSort[list,p],n]:

https://wolfram.com/xid/0gfriki0zkdy-ukwaab


https://wolfram.com/xid/0gfriki0zkdy-c307t7


https://wolfram.com/xid/0gfriki0zkdy-610muf

TakeLargest uses NumericalOrder as default ordering function p:

https://wolfram.com/xid/0gfriki0zkdy-eh1mtg

Using canonical order can give different results:

https://wolfram.com/xid/0gfriki0zkdy-fhbzgs

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

https://wolfram.com/xid/0gfriki0zkdy-fd5f3m

https://wolfram.com/xid/0gfriki0zkdy-bhlinu


https://wolfram.com/xid/0gfriki0zkdy-fpbt56

Comparisons of non-numerical elements effectively follow canonical order:

https://wolfram.com/xid/0gfriki0zkdy-ybsnr0

https://wolfram.com/xid/0gfriki0zkdy-hajge3


https://wolfram.com/xid/0gfriki0zkdy-r5q334

Order is the default ordering function for Sort and ReverseSort:

https://wolfram.com/xid/0gfriki0zkdy-zdwvzn

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

https://wolfram.com/xid/0gfriki0zkdy-rqcrip


https://wolfram.com/xid/0gfriki0zkdy-1lck47

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

https://wolfram.com/xid/0gfriki0zkdy-3xmep8


https://wolfram.com/xid/0gfriki0zkdy-j2l8sq

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

https://wolfram.com/xid/0gfriki0zkdy-srz1tv

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

https://wolfram.com/xid/0gfriki0zkdy-85ikhw


https://wolfram.com/xid/0gfriki0zkdy-3bn1ei

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

https://wolfram.com/xid/0gfriki0zkdy-u1qjai


https://wolfram.com/xid/0gfriki0zkdy-fgf71e


https://wolfram.com/xid/0gfriki0zkdy-v5pdof

Take a list of five dates in the current year:

https://wolfram.com/xid/0gfriki0zkdy-lvdwsa

Get the two latest of the dates with TakeLargest:

https://wolfram.com/xid/0gfriki0zkdy-pxkjvb

Get the second latest of the dates with RankedMax:

https://wolfram.com/xid/0gfriki0zkdy-r0w16e

Possible Issues (2)Common pitfalls and unexpected behavior
If fewer than the requested number of elements are present, TakeLargest will not evaluate:

https://wolfram.com/xid/0gfriki0zkdy-wv21bw


Use UpTo to get as many elements as possible:

https://wolfram.com/xid/0gfriki0zkdy-pu5pzo

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

https://wolfram.com/xid/0gfriki0zkdy-wkg1mn


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).
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.
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
Wolfram Language. (2015). TakeLargest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TakeLargest.html
BibTeX
@misc{reference.wolfram_2025_takelargest, author="Wolfram Research", title="{TakeLargest}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/TakeLargest.html}", note=[Accessed: 21-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_takelargest, organization={Wolfram Research}, title={TakeLargest}, year={2025}, url={https://reference.wolfram.com/language/ref/TakeLargest.html}, note=[Accessed: 21-April-2025
]}