Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Drop the largest values from a list based on a function
| ResourceFunction["DropLargestBy"][list,f,n] drops the n elements ei in list for which f[ei] is largest. | |
| ResourceFunction["DropLargestBy"][f,n] represents an operator form of ResourceFunction["DropLargestBy"]. | 
Drop the largest two values:
| In[1]:= | ![ResourceFunction["DropLargestBy"][{1, -5, 3, -8, -4, 2, 9}, Abs, 2]](https://www.wolframcloud.com/obj/resourcesystem/images/0dc/0dcb7712-5d7e-4586-b19d-ebe94b4f38ac/601afc4986a20d76.png) | 
| Out[1]= |  | 
Use the operator form, by first creating an operator op:
| In[2]:= | ![op = ResourceFunction["DropLargestBy"][Abs, 2]](https://www.wolframcloud.com/obj/resourcesystem/images/0dc/0dcb7712-5d7e-4586-b19d-ebe94b4f38ac/0f275b5699c3140d.png) | 
| Out[2]= |  | 
Apply the operator:
| In[3]:= | ![op[{1, -5, 3, -8, -4, 2, 9}]](https://www.wolframcloud.com/obj/resourcesystem/images/0dc/0dcb7712-5d7e-4586-b19d-ebe94b4f38ac/01f9bb8933995656.png) | 
| Out[3]= |  | 
With n=0 nothing is deleted:
| In[4]:= | ![ResourceFunction["DropLargestBy"][{1, 5, 3, 8, 4, 2, 9}, Abs, 0]](https://www.wolframcloud.com/obj/resourcesystem/images/0dc/0dcb7712-5d7e-4586-b19d-ebe94b4f38ac/0f58290e3c10348a.png) | 
| Out[4]= |  | 
A negative number deletes the smallest n numbers:
| In[5]:= | ![ResourceFunction["DropLargestBy"][{1, -5, 3, -8, -4, 2, 9}, Abs, -2]](https://www.wolframcloud.com/obj/resourcesystem/images/0dc/0dcb7712-5d7e-4586-b19d-ebe94b4f38ac/1c0a37b0ef0e6a9a.png) | 
| Out[5]= |  | 
If n is larger than the length of the list then an empty list is returned:
| In[6]:= | ![ResourceFunction["DropLargestBy"][{1, -5, 3, -8, -4, 2, 9}, Sign, 12]](https://www.wolframcloud.com/obj/resourcesystem/images/0dc/0dcb7712-5d7e-4586-b19d-ebe94b4f38ac/4aa0f19061faafda.png) | 
| Out[6]= |  | 
DropLargestBy is complementary to TakeLargestBy:
| In[7]:= |  | 
| In[8]:= | ![ResourceFunction["DropLargestBy"][in, Abs, 3]](https://www.wolframcloud.com/obj/resourcesystem/images/0dc/0dcb7712-5d7e-4586-b19d-ebe94b4f38ac/22bfef0f218297ab.png) | 
| Out[8]= |  | 
| In[9]:= | ![TakeLargestBy[in, Abs, 3]](https://www.wolframcloud.com/obj/resourcesystem/images/0dc/0dcb7712-5d7e-4586-b19d-ebe94b4f38ac/2153c07d567f7b87.png) | 
| Out[9]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License