TakeLargestBy

TakeLargestBy[list,f,n]

gives the n elements ei in list for which f[ei] is largest, sorted in descending order.

TakeLargestBy[listprop,f,n]

gives the property prop for the n elements in list for which f[ei] is largest.

TakeLargestBy[f,n]

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

Details and Options

Examples

open all close all

Basic Examples  (3)

Take the two longest strings in a list:

In[1]:=
Click for copyable input
Out[1]=

Do the same using the operator form of TakeLargestBy:

In[2]:=
Click for copyable input
Out[2]=

Take the two longest strings in an association:

In[3]:=
Click for copyable input
Out[3]=

Give the four numbers farthest from zero:

In[1]:=
Click for copyable input
Out[1]=

Give the 4 numbers farthest from zero, or as many as are available if fewer:

In[1]:=
Click for copyable input
Out[1]=

Scope  (5)

Applications  (1)

Possible Issues  (2)

Neat Examples  (1)

Introduced in 2015
(10.1)
|
Updated in 2019
(12.0)