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.

更多信息

  • 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]. »

范例

打开所有单元关闭所有单元

基本范例  (4)

根据后面数据的大小,找出最小的元素:

Do the same using the operator form of MinimalBy:

按出现的先后顺序,返回所有最小元素:

获取前三个最小的元素:

Prune an association to its minimal values:

范围  (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:

应用  (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:

属性和关系  (3)

MinimalBy[{e1,e2,},f,n] 用标准 Order 对值 f[ei] 进行比较:

TakeSmallestBy[{e1,e2,},f,n]NumericalOrder 对值 f[ei] 进行比较:

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:

可能存在的问题  (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 语言函数,https://reference.wolfram.com/language/ref/MinimalBy.html (更新于 2025 年).

文本

Wolfram Research (2014),MinimalBy,Wolfram 语言函数,https://reference.wolfram.com/language/ref/MinimalBy.html (更新于 2025 年).

CMS

Wolfram 语言. 2014. "MinimalBy." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/MinimalBy.html.

APA

Wolfram 语言. (2014). MinimalBy. Wolfram 语言与系统参考资料中心. 追溯自 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: 02-February-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: 02-February-2025 ]}