# MinimalBy

MinimalBy[{e1,e2,},f]

returns a list of the ei for which the value of f[ei] is minimal.

MinimalBy[{e1,e2,},f,n]

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

MinimalBy[f]

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

# Details

• Values of f[ei] are compared using the same canonical order as in Sort.
• The minimal ei are returned in the order they appear in the input.
• In the case of MinimalBy[list,f,n], the ei are 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 list.
• MinimalBy[list,f, UpTo[n]] gives n elements, or as many as are available.
• MinimalBy[f][expr] is equivalent to MinimalBy[expr,f].
• In MinimalBy[assoc, f, ], f is applied to the values of the association assoc.

# Examples

open allclose all

## Basic Examples(4)

Find the minimal element by its last part:

All minimal elements are returned, in order of appearance:

Obtain the first three minimal elements:

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

## Scope(1)

MinimalBy works with symbolic expressions, using OrderedQ:

## Properties & Relations(1)

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

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

## Possible Issues(1)

The minimal element is determined using OrderedQ, not numerical ordering:

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

#### Text

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

#### CMS

Wolfram Language. 2014. "MinimalBy." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. 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_2022_minimalby, author="Wolfram Research", title="{MinimalBy}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/MinimalBy.html}", note=[Accessed: 05-December-2022 ]}

#### BibLaTeX

@online{reference.wolfram_2022_minimalby, organization={Wolfram Research}, title={MinimalBy}, year={2015}, url={https://reference.wolfram.com/language/ref/MinimalBy.html}, note=[Accessed: 05-December-2022 ]}