MaximalBy

MaximalBy[{e1,e2,},f]

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

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

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

MaximalBy[f]

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

Details • Values of f[ei] are compared using the same canonical order as in Sort.
• The maximal ei are returned in the order they appear in the input.
• In the case of MaximalBy[list,f,n], the ei are sorted in the order of decreasing f[ei], with those having the same value of f[ei] being taken in the order they appear in list.
• MaximalBy[list,f, UpTo[n]] gives n elements, or as many as are available.
• MaximalBy[f][expr] is equivalent to MaximalBy[expr,f].

Examples

open all close all

Basic Examples(4)

Find the maximal element by last part:

 In:= Out= All maximal elements are returned, in order of appearance:

 In:= Out= Obtain the first three maximal elements:

 In:= Out= Obtain the first 4 maximal elements, or as many as are available:

 In:= Out= Possible Issues(3)

Introduced in 2014
(10.0)
|
Updated in 2015
(10.3)