MinimalBy

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.

MinimalBy[f]

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)

Find the minimal element by its last part:

Do the same using the operator form of MinimalBy:

All minimal elements are returned, in order of appearance:

Obtain the first three minimal elements:

Prune an association to its minimal values:

Scope  (10)

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

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

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

Comparing by QuantityMagnitude loses the unit information:

Find numerically smallest element:

MinimalBy works on QuantityArray:

MinimalBy will order dates according to canonical order by default:

Convert the dates to absolute times to sort them numerically:

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

Take the letters of the Polish alphabet:

Transliterate them to the Hiragana script:

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

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

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

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

Construct a TabularColumn object with 100 words:

Select the five longest words:

Normalize the result to a list:

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

Use general functional notation instead of the column name:

Use function of both columns:

Take a dataset of the solar system planets:

Find the three planets with the minimal number of moons:

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

Applications  (3)

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

Find the five constellations with minimal number of bright stars:

Take a dataset of the solar system planets:

Find the two planets with the minimal mass:

Properties & Relations  (3)

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

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

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

For association, the function f is applied to values:

Possible Issues  (1)

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

Compare numerical values of the elements of the list:

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).

CMS

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

BibTeX

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

BibLaTeX

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