TakeSmallest
TakeSmallest[data,n]
gives the n smallest elements of data, sorted in ascending order.
TakeSmallest[dataprop,n]
gives the property prop for the n smallest elements in data.
TakeSmallest[data,n,p]
uses the order function p for sorting.
TakeSmallest[n]
represents an operator form of TakeSmallest that can be applied to an expression.
Details and Options
- TakeSmallest gives the smallest elements in the first level of the input data. »
- By default, TakeSmallest uses NumericalOrder to sort numeric expressions, Quantity objects and DateObject expressions. For other types of objects, TakeSmallest sorts by canonical Order.
- 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 » - TakeSmallest[assoc,n] gives an association of length n by taking the n smallest values in assoc, preserving their keys.
- In TakeSmallest[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 » - TakeSmallest[data,UpTo[n]] takes n smallest elements, or as many as are available. »
- TakeSmallest[n][data] is equivalent to TakeSmallest[data,n].
- TakeSmallest has option ExcludedForms. With the default setting ExcludedForms->Automatic, TakeSmallest 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 TakeSmallest. »
Examples
open allclose allBasic Examples (4)
Take the two smallest numbers in a list:
Do the same using the operator form of TakeSmallest:
Get the three smallest quantities in a list of Quantity objects:
Quantities can be present in multiple units:
Get the two least recent dates in a list of DateObject constructs:
Scope (9)
Take the four smallest 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 smallest elements in a list:
Get the positions of the two smallest elements in a list:
Get the two smallest elements in a list along with their positions:
Get the two smallest elements in a list with their positions given first:
Get associations containing the element and position of the two smallest elements in a list:
Find the three smallest elements in a TabularColumn:
Get the four rows with the smallest element in the first column in a Tabular object:
Take a list of numeric expressions or infinities:
By default, TakeSmallest 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 NumericalOrder, TakeSmallest 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, TakeSmallest takes all elements into account when finding the smallest ones:
Applications (6)
Get the three planets with the smallest radii:
Get the release dates of the five oldest James Bond movies:
Find the South American countries with the lowest life expectancy for their inhabitants:
Find the codons (groups of three consecutive nucleotides) with the lowest relative frequencies in the list of nucleotides of a gene:
Find the noble gases with the lowest boiling point and density:
Properties & Relations (6)
TakeSmallest[list,n,p] is effectively equivalent to Take[Sort[list,p],n]:
TakeSmallest uses NumericalOrder as default ordering function p:
Using canonical order can give different results:
With numerical inputs, the result of TakeSmallest is determined by numerical comparisons:
Comparisons of non-numerical elements effectively follow canonical order:
Order is the default ordering function for Sort and ReverseSort:
TakeSmallest[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 Min, TakeSmallest does not return values at deeper levels:
When different numerical expressions have the same value, their original order will be preserved:
TakeSmallest[list,n,p] is effectively equivalent to MinimalBy[list,Identity,n,p]:
Take a list of five dates in the current year:
Get the two earliest of the dates with TakeSmallest:
Get the second earliest of the dates with RankedMin:
Possible Issues (2)
If fewer than the requested number of elements are present, TakeSmallest will not evaluate:
Use UpTo to get as many elements as possible:
If the elements are not comparable, TakeSmallest will not evaluate:
Text
Wolfram Research (2015), TakeSmallest, Wolfram Language function, https://reference.wolfram.com/language/ref/TakeSmallest.html (updated 2025).
CMS
Wolfram Language. 2015. "TakeSmallest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/TakeSmallest.html.
APA
Wolfram Language. (2015). TakeSmallest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TakeSmallest.html