Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Drop the smallest values from a list based on a function
ResourceFunction["DropSmallestBy"][list,f,n] drops the n elements ei from list for which f[ei] is smallest. | |
ResourceFunction["DropSmallestBy"][f,n] represents an operator form of ResourceFunction["DropSmallestBy"] that can be applied to an expression. |
Drop the smallest two values determined by their magnitude:
In[1]:= |
Out[1]= |
Drop the smallest two complex values determined by their magnitude:
In[2]:= |
Out[2]= |
Use the operator form, by first creating an operator op:
In[3]:= |
Out[3]= |
Apply the operator:
In[4]:= |
Out[4]= |
When n=0, nothing is deleted:
In[5]:= |
Out[5]= |
A negative number deletes the largest n numbers:
In[6]:= |
Out[6]= |
If n is larger than the length of the list, an empty list is returned:
In[7]:= |
Out[7]= |
DropSmallestBy and TakeSmallestBy are complementary:
In[8]:= |
In[9]:= |
Out[9]= |
In[10]:= |
Out[10]= |
This work is licensed under a Creative Commons Attribution 4.0 International License