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.
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
- 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 all close allBasic Examples (4)
Take the two largest numbers in a list:
TakeLargest[{1, 3, 5, 4}, 2]Do the same using the operator form of TakeLargest:
{1, 3, 5, 4}//TakeLargest[2]TakeLargest[2] @ {1, 3, 5, 4, 2}Get the three largest quantities in a list of Quantity objects:
TakeLargest[{Quantity[1, "Kilograms"], Quantity[2, "Kilograms"], Quantity[3, "Kilograms"], Quantity[4, "Kilograms"]}, 3]Quantities can be present in multiple units:
TakeLargest[{Quantity[1, "Grams"], Quantity[2, "Kilograms"], Quantity[3, "Milligrams"], Quantity[4, "Micrograms"]}, 3]Get the two latest dates in a list of DateObject constructs:
TakeLargest[{Yesterday, Today, Tomorrow}, 2]Take the three largest values in an association:
TakeLargest[<|a -> 1, b -> 2, c -> 3, d -> 4, e -> 5|>, 3]Scope (9)
Take the four largest numbers, or as many as are available if fewer:
TakeLargest[{1, 7, 4}, UpTo[4]]Quantities can be given as QuantityArray:
TakeLargest[QuantityArray[{1, 2, 3}, "kg"], 2]Normal[%]By default, Missing[] and several other symbolic expressions are excluded from the results:
TakeLargest[{1, 3, 5, None, Indeterminate, Missing[]}, 2]Get the two largest elements in a list:
list = {E^π, 7 π, π^E, 23};TakeLargest[list -> "Element", 2]Get the positions of the two largest elements in a list:
TakeLargest[list -> "Index", 2]Get the two largest elements in a list along with their positions:
TakeLargest[list -> {"Element", "Index"}, 2]Get the two largest elements in a list with their positions given first:
TakeLargest[list -> {"Index", "Element"}, 2]Get associations containing the element and position of the two largest elements in a list:
TakeLargest[list -> All, 2]Find the three largest elements in a TabularColumn object:
TabularColumn[{16.1, 29.2, 33.8, 14.7, 30.1, 27.5, 36., 35.1}]TakeLargest[%, 3]Normal[%]Get the four rows with the largest elements in the first column in a Tabular object:
data = {{8, 13, 18, 8, 14, 13, 18, 17}, {16.1, 29.2, 23.8, 14.7, 30.1, 27.5, 35.1, 36.2}};
tab = ToTabular[data, "Columns", {"size", "length"}]Ties in the first column are resolved by comparing values in the second column:
TakeLargest[tab, 4]Normal[%]Take a list of numeric expressions or infinities:
list = {E^π, 7 π, π^E, 23, -Infinity};By default, TakeLargest sorts the elements using NumericalOrder:
TakeLargest[list, 3]ReverseSort[list, NumericalOrder]Use canonical Order instead:
TakeLargest[list, 3, Order]ReverseSort[list]Take a list of lists of integers:
list = {{3, 7}, {2, 7, 2}, {0, 1, 3, 4}};They are not numeric elements, so they are sorted by default following canonical order:
TakeLargest[list, 2]ReverseSort[list]Use instead lexicographic order, which will sort the list by their respective first elements:
TakeLargest[list, 2, LexicographicOrder]ReverseSort[list, LexicographicOrder]Take a list of complex numbers:
list = RandomComplex[{-10 - 10I, 10 + 10I}, 5]Following reverse NumericalOrder, TakeLargest selects numbers with decreasing real part:
TakeLargest[list, 3]ReverseSort[list, NumericalOrder]Options (2)
ExcludedForms (2)
By default, Missing[] and several other symbolic expressions are excluded from the results:
TakeLargest[{1, 3, 5, None, Indeterminate, Missing[]}, 2]Specify which elements should be excluded:
TakeLargest[{1, 3, 5, None, Indeterminate, Missing[]}, 2, ExcludedForms -> {None, Indeterminate}]By default, TakeLargest takes all elements into account when finding the largest ones:
TakeLargest[{6, -3, 4, x, 2, y, z}, 3]TakeLargest[{6, -3, 4, x, 2, y, z}, 3, ExcludedForms -> {x, y}]Exclude elements matching a given pattern:
TakeLargest[{6, -3, 4, x, 2, y, z}, 3, ExcludedForms -> {_Symbol}]Applications (6)
Get the three planets with the largest radii:
TakeLargest[EntityValue["Planet", "Radius", "EntityAssociation"], 3]Get the release dates of the five most recent James Bond movies:
TakeLargest[EntityValue[EntityClass["Movie", "JamesBondFranchise"], EntityProperty["Movie", "ReleaseDate"], "EntityAssociation"], 5]Find the South American countries with the highest life expectancy for their inhabitants:
data = EntityValue[EntityClass["Country", "SouthAmerica"], EntityProperty["Country", "LifeExpectancy"], "EntityAssociation"];TakeLargest[data, 2]Find the codons (groups of three consecutive nucleotides) with the highest relative frequencies in the list of nucleotides of a gene:
dnasequence = GenomeData["SCNN1A", "FullSequence"];
codons = StringPartition[dnasequence, 3];
frequencies = N[Counts[codons] / Length[codons]];TakeLargest[frequencies, 3]Find the noble gases with the highest boiling point and density:
gases = EntityValue[EntityClass["Element", "NobleGas"], {"BoilingPoint", "Density"}, "Dataset"]gases[TakeLargest[2], "BoilingPoint"]gases[TakeLargest[2], "Density"]Find the five densest chemical elements:
EntityValue[EntityClass["Element", All], "Density", "EntityAssociation"]//TakeLargest[5]Properties & Relations (6)
TakeLargest[list,n,p] is effectively equivalent to Take[ReverseSort[list,p],n]:
list = Sqrt /@ RandomInteger[1000, 6]Take[ReverseSort[list, NumericalOrder], 2]TakeLargest[list, 2]TakeLargest uses NumericalOrder as default ordering function p:
TakeLargest[list, 2, NumericalOrder]Using canonical order can give different results:
TakeLargest[list, 2, Order]With numerical inputs, the result of TakeLargest is determined by numerical comparisons:
list = {1, 7, 4, 6, 2};TakeLargest[list, 3]ReverseSort[list, NumericalOrder]Comparisons of non-numerical elements effectively follow canonical order:
list = {1, 7, a, 4, 6, 2, b};TakeLargest[list, 3]ReverseSort[list, Order]Order is the default ordering function for Sort and ReverseSort:
ReverseSort[list]TakeLargest[data,…] operates at the first level of the input data:
RandomInteger[100, 10]TakeLargest[%, 3]If the input has several levels, it is still elements of the first level that will be sorted and extracted:
RandomInteger[100, {5, 2}]TakeLargest[%, 3]Unlike Max, TakeLargest does not return values at deeper levels:
Max[%%]When different numerical expressions have the same value, their original order will be preserved:
TakeLargest[{1, 2, 4., 3, 4}, 3]TakeLargest[{1, 2, 4, 3, 4.}, 3]TakeLargest[list,n,p] is effectively equivalent to MaximalBy[list,Identity,n,p]:
list = Quantity[RandomReal[10, 5], "Knots"]TakeLargest[list, 3]MaximalBy[list, Identity, 3, NumericalOrder]Take a list of five dates in the current year:
list = RandomDate[5]Get the two latest of the dates with TakeLargest:
TakeLargest[list, 2]Get the second latest of the dates with RankedMax:
RankedMax[list, 2]Possible Issues (2)
If fewer than the requested number of elements are present, TakeLargest will not evaluate:
TakeLargest[{3, 1, 2}, 5]Use UpTo to get as many elements as possible:
TakeLargest[{3, 1, 2}, UpTo[5]]If the elements are not comparable, TakeLargest will not evaluate:
TakeLargest[{Quantity[1, "Hour"], Quantity[5, "Joules"]}, 1]See Also
TakeLargestBy MaximalBy Max PositionLargest ReverseSort ReverseSortBy NumericalSort NumericalOrder Ordering RankedMax TakeSmallest TakeSmallestBy
Function Repository: DropLargest PositionLargest TakeLarger TakeAfter
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_2026_takelargest, author="Wolfram Research", title="{TakeLargest}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/TakeLargest.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_takelargest, organization={Wolfram Research}, title={TakeLargest}, year={2025}, url={https://reference.wolfram.com/language/ref/TakeLargest.html}, note=[Accessed: 12-June-2026]}