MinimalBy
✖
MinimalBy
returns a list of the elements ei of data corresponding to the n smallest f[ei].
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 allBasic Examples (4)Summary of the most common use cases
Find the minimal element by its last part:

https://wolfram.com/xid/0d6esg9sjx-dmyv5c

Do the same using the operator form of MinimalBy:

https://wolfram.com/xid/0d6esg9sjx-ips7ik

All minimal elements are returned, in order of appearance:

https://wolfram.com/xid/0d6esg9sjx-flbadk

Obtain the first three minimal elements:

https://wolfram.com/xid/0d6esg9sjx-sk5d65

Prune an association to its minimal values:

https://wolfram.com/xid/0d6esg9sjx-qfcnla

Scope (10)Survey of the scope of standard use cases
Obtain the first four minimal elements or as many as are available:

https://wolfram.com/xid/0d6esg9sjx-cxz194

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

https://wolfram.com/xid/0d6esg9sjx-h8pa7q

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

https://wolfram.com/xid/0d6esg9sjx-7h95kn
Comparing by QuantityMagnitude loses the unit information:

https://wolfram.com/xid/0d6esg9sjx-m9komw

Find numerically smallest element:

https://wolfram.com/xid/0d6esg9sjx-mb7ykx

MinimalBy works on QuantityArray:

https://wolfram.com/xid/0d6esg9sjx-5095u0


https://wolfram.com/xid/0d6esg9sjx-27ls1w

MinimalBy will order dates according to canonical order by default:

https://wolfram.com/xid/0d6esg9sjx-8io75q

https://wolfram.com/xid/0d6esg9sjx-egsswk

Convert the dates to absolute times to sort them numerically:

https://wolfram.com/xid/0d6esg9sjx-2cfbnt

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

https://wolfram.com/xid/0d6esg9sjx-cgess

Take the letters of the Polish alphabet:

https://wolfram.com/xid/0d6esg9sjx-2tqvoa

Transliterate them to the Hiragana script:

https://wolfram.com/xid/0d6esg9sjx-poa4o

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

https://wolfram.com/xid/0d6esg9sjx-ir8ogd

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

https://wolfram.com/xid/0d6esg9sjx-3s7mz6

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

https://wolfram.com/xid/0d6esg9sjx-lvc9m8

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

https://wolfram.com/xid/0d6esg9sjx-1f7udk

Construct a TabularColumn object with 100 words:

https://wolfram.com/xid/0d6esg9sjx-ss77bg

Select the five longest words:

https://wolfram.com/xid/0d6esg9sjx-ije4w6

Normalize the result to a list:

https://wolfram.com/xid/0d6esg9sjx-5kepgn

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

https://wolfram.com/xid/0d6esg9sjx-jpfbrr


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

Use general functional notation instead of the column name:

https://wolfram.com/xid/0d6esg9sjx-2shaqt


https://wolfram.com/xid/0d6esg9sjx-r1yvkm

Take a dataset of the solar system planets:

https://wolfram.com/xid/0d6esg9sjx-2sxsoh

Find the three planets with the minimal number of moons:

https://wolfram.com/xid/0d6esg9sjx-3981jc

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

https://wolfram.com/xid/0d6esg9sjx-eie171


https://wolfram.com/xid/0d6esg9sjx-7xt8dc


https://wolfram.com/xid/0d6esg9sjx-3qjjjv

Applications (3)Sample problems that can be solved with this function
Find the four shortest texts available in ExampleData["Text"]:

https://wolfram.com/xid/0d6esg9sjx-ug532s

Find the five constellations with minimal number of bright stars:

https://wolfram.com/xid/0d6esg9sjx-5wk7hj

Take a dataset of the solar system planets:

https://wolfram.com/xid/0d6esg9sjx-zm3ura

Find the two planets with the minimal mass:

https://wolfram.com/xid/0d6esg9sjx-j98ou9

Properties & Relations (3)Properties of the function, and connections to other functions
MinimalBy[{e1,e2,…},f,n] compares values f[ei] using canonical Order:

https://wolfram.com/xid/0d6esg9sjx-ek5f73

https://wolfram.com/xid/0d6esg9sjx-d1gqp2


https://wolfram.com/xid/0d6esg9sjx-trdyiu

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

https://wolfram.com/xid/0d6esg9sjx-dfljwn


https://wolfram.com/xid/0d6esg9sjx-82pmav

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

https://wolfram.com/xid/0d6esg9sjx-tcosjd


https://wolfram.com/xid/0d6esg9sjx-zmikml


https://wolfram.com/xid/0d6esg9sjx-9ev6xw

For association, the function f is applied to values:

https://wolfram.com/xid/0d6esg9sjx-85vbbb

https://wolfram.com/xid/0d6esg9sjx-h7llui

Possible Issues (1)Common pitfalls and unexpected behavior
By default, the minimal element is determined using canonical Order, not numerical ordering:

https://wolfram.com/xid/0d6esg9sjx-8wjy5i


https://wolfram.com/xid/0d6esg9sjx-nt8yvj

Compare numerical values of the elements of the list:

https://wolfram.com/xid/0d6esg9sjx-gcknls


https://wolfram.com/xid/0d6esg9sjx-68xbc

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
]}
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
]}