WOLFRAM

MinimalBy[data,f]

returns a list of the elements ei of data for which the value of f is minimal.

MinimalBy[data,f,n]

returns a list of the elements ei of data corresponding to the n smallest f[ei].

MinimalBy[data,f,n,p]

uses the ordering function p for sorting.

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

Details

  • By default, values of f[ei] are compared using Order, the same canonical order as in Sort.
  • MinimalBy[data,f] returns the list of minimal elements ei of data in the order they appear in the input.
  • MinimalBy[data,f,n] returns the ei sorted in the order of increasing f[ei], with those having the same value of f[ei] being taken in the order they appear in 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 »
  • For tabular data tab, MinimalBy[tab,f,] applies the function f to individual rows of tab, with the row being an association <|col1val1,|> if tab has column keys or a list {val1,} if tab does not have column keys.
  • MinimalBy[data,f, UpTo[n]] gives n elements or as many as are available. »
  • MinimalBy[f][data] is equivalent to MinimalBy[data,f]. »

Examples

open allclose all

Basic Examples  (4)Summary of the most common use cases

Find the minimal element by its last part:

Out[1]=1

Do the same using the operator form of MinimalBy:

Out[1]=1

All minimal elements are returned, in order of appearance:

Out[1]=1

Obtain the first three minimal elements:

Out[1]=1

Prune an association to its minimal values:

Out[1]=1

Scope  (10)Survey of the scope of standard use cases

Obtain the first four minimal elements or as many as are available:

Out[1]=1

MinimalBy works with symbolic expressions, using canonical Order by default:

Out[1]=1

Find minimal element in a list of comparable quantities with various units:

Comparing by QuantityMagnitude loses the unit information:

Out[2]=2

Find numerically smallest element:

Out[3]=3

MinimalBy works on QuantityArray:

Out[1]=1
Out[2]=2

MinimalBy will order dates according to canonical order by default:

Out[2]=2

Convert the dates to absolute times to sort them numerically:

Out[3]=3

Equivalently, convert the dates to DateObject form and use NumericalOrder instead of Order:

Out[4]=4

Take the letters of the Polish alphabet:

Out[1]=1

Transliterate them to the Hiragana script:

Out[2]=2

These are the five smallest Polish letters according to canonical order:

Out[3]=3

These are the five smallest Polish letters according to the rules of the Polish alphabet:

Out[4]=4

These are the five smallest Polish letters according to canonical order of their Hiragana transliteration:

Out[5]=5

These are the five smallest Polish letters according to alphabetic order in Japanese of their transliteration:

Out[6]=6

Construct a TabularColumn object with 100 words:

Out[1]=1

Select the five longest words:

Out[2]=2

Normalize the result to a list:

Out[3]=3

Find the four rows in a Tabular object with minimal value in a specified column:

Out[1]=1
Out[2]=2

Use general functional notation instead of the column name:

Out[3]=3

Use function of both columns:

Out[4]=4

Take a dataset of the solar system planets:

Out[1]=1

Find the three planets with the minimal number of moons:

Out[2]=2

When there are common values of f[ei] for different elements ei, the original order will be kept:

Out[1]=1
Out[2]=2
Out[3]=3

Applications  (3)Sample problems that can be solved with this function

Find the four shortest texts available in ExampleData["Text"]:

Out[1]=1

Find the five constellations with minimal number of bright stars:

Out[1]=1

Take a dataset of the solar system planets:

Out[1]=1

Find the two planets with the minimal mass:

Out[2]=2

Properties & Relations  (3)Properties of the function, and connections to other functions

MinimalBy[{e1,e2,},f,n] compares values f[ei] using canonical Order:

Out[2]=2
Out[3]=3

TakeSmallestBy[{e1,e2,},f,n] compares values f[ei] using NumericalOrder:

Out[4]=4
Out[5]=5

For a specific ordering function p, MinimalBy[data,f,n,p] is equivalent to TakeSmallestBy[data,f,n,p]:

Out[1]=1
Out[2]=2
Out[3]=3

For association, the function f is applied to values:

Out[2]=2

Possible Issues  (1)Common pitfalls and unexpected behavior

By default, the minimal element is determined using canonical Order, not numerical ordering:

Out[4]=4
Out[5]=5

Compare numerical values of the elements of the list:

Out[6]=6
Out[7]=7
Wolfram Research (2014), MinimalBy, Wolfram Language function, https://reference.wolfram.com/language/ref/MinimalBy.html (updated 2025).
Wolfram Research (2014), MinimalBy, Wolfram Language function, https://reference.wolfram.com/language/ref/MinimalBy.html (updated 2025).

Text

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

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

CMS

Wolfram Language. 2014. "MinimalBy." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/MinimalBy.html.

Wolfram Language. 2014. "MinimalBy." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/MinimalBy.html.

APA

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

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

BibTeX

@misc{reference.wolfram_2025_minimalby, author="Wolfram Research", title="{MinimalBy}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/MinimalBy.html}", note=[Accessed: 16-April-2025 ]}

@misc{reference.wolfram_2025_minimalby, author="Wolfram Research", title="{MinimalBy}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/MinimalBy.html}", note=[Accessed: 16-April-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_minimalby, organization={Wolfram Research}, title={MinimalBy}, year={2025}, url={https://reference.wolfram.com/language/ref/MinimalBy.html}, note=[Accessed: 16-April-2025 ]}

@online{reference.wolfram_2025_minimalby, organization={Wolfram Research}, title={MinimalBy}, year={2025}, url={https://reference.wolfram.com/language/ref/MinimalBy.html}, note=[Accessed: 16-April-2025 ]}