Function Repository Resource:

TakeLarger

Source Notebook

Take values larger than a threshold in a list or association

Contributed by: Wolfram staff

ResourceFunction["TakeLarger"][list,val,n]

gives the smallest n elements in list that are larger than val.

ResourceFunction["TakeLarger"][listprop,val,n]

gives the property prop for the n elements in list larger than val.

ResourceFunction["TakeLarger"][val,n]

represents an operator form of ResourceFunction["TakeLarger"] that can be applied to an expression.

Details and Options

ResourceFunction["TakeLarger"] sorts by numerical magnitude.
ResourceFunction["TakeLarger"] handles the same objects and properties as TakeLargest.
ResourceFunction["TakeLarger"] expects all objects to be comparable with one another.
ResourceFunction["TakeLarger"][list,val,UpTo[n]] takes n elements, or as many as are available.
ResourceFunction["TakeLarger"][assoc,val,n] gives an association of length n by taking the n smallest values that are larger than val in assoc, preserving their keys.
ResourceFunction["TakeLarger"][val,n][list] is equivalent to ResourceFunction["TakeLarger"][list,val,n].

Examples

Basic Examples (5) 

Take two numbers larger than the specified value in a list:

In[1]:=
list = {1, 3, 5, 4}
Out[1]=
In[2]:=
ResourceFunction["TakeLarger"][list, 3, 2]
Out[2]=

Do the same using the operator form of TakeLarger:

In[3]:=
list // ResourceFunction["TakeLarger"][3, 2]
Out[3]=
In[4]:=
ResourceFunction["TakeLarger"][3, 2] @ list
Out[4]=

Take the smallest two values larger then the specified threshold in an association:

In[5]:=
ResourceFunction[
 "TakeLarger"][<|a -> 1, b -> 2, c -> 3, d -> 5, e -> 4|>, 3, 2]
Out[5]=

Take the smallest four numbers larger than the specified value, or as many as are available:

In[6]:=
ResourceFunction["TakeLarger"][{1, 7, 4}, 3, UpTo[4]]
Out[6]=

Take all numbers larger than a threshold:

In[7]:=
ResourceFunction["TakeLarger"][{1, 7, 4, 5}, 3, UpTo[Infinity]]
Out[7]=

Take two values in a list of Quantity objects:

In[8]:=
ResourceFunction[
 "TakeLarger"][{Quantity[1, "Kilograms"], Quantity[2, "Kilograms"], Quantity[3, "Kilograms"]}, Quantity[1, "Kilograms"], 2]
Out[8]=

Scope (3) 

Get the two smallest elements that are larger than 3 in a list:

In[9]:=
ResourceFunction["TakeLarger"][{E^\[Pi], 7 \[Pi], \[Pi]^E, 23}, 3, 2]
Out[9]=

Get the positions of the two smallest elements larger than 3:

In[10]:=
list = {E^\[Pi], 7 \[Pi], \[Pi]^E, 23};
In[11]:=
ResourceFunction["TakeLarger"][list -> "Index", 3, 2]
Out[11]=

Get the elements along with their positions:

In[12]:=
ResourceFunction["TakeLarger"][list -> {"Element", "Index"}, 3, 2]
Out[12]=

Let positions come first in the result:

In[13]:=
ResourceFunction["TakeLarger"][list -> {"Index", "Element"}, 3, 2]
Out[13]=

Get associations containing the element and the position:

In[14]:=
ResourceFunction["TakeLarger"][list -> All, 3, 2]
Out[14]=

Get the two smallest planets with the radii larger than the Earth:

In[15]:=
ResourceFunction["TakeLarger"][
 EntityValue["Planet", "Radius", "EntityAssociation"], Entity["Planet", "Earth"]["Radius"], 2]
Out[15]=

Version History

  • 2.0.0 – 19 September 2019
  • 1.0.0 – 08 July 2019

Related Resources

License Information