Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Group small values in an association into a single category
ResourceFunction["AggregateSmallest"][assoc,x] sums values below x in Association assoc into a single number. | |
ResourceFunction["AggregateSmallest"][assoc,Scaled[factor]] sums small values in Association assoc into a single category no larger than a proportion factor of the total. | |
ResourceFunction["AggregateSmallest"][{assoc1,assoc2,…},x] sums aggregates each Association into a common categorization. |
Group all keys with values of 1 or less into a new "Other" key:
In[1]:= | ![]() |
Out[1]= | ![]() |
Group small values into an "Other" category that contains up to 50% of the total:
In[2]:= | ![]() |
Out[2]= | ![]() |
When multiple associations are provided a common categorization is established:
In[3]:= | ![]() |
Out[3]= | ![]() |
AggregateSmallest is designed to simplify the result of Counts. For example, this PieChart is unreadable for infrequent categories:
In[4]:= | ![]() |
Out[4]= | ![]() |
Aggregating 20% of the data makes the pie chart simpler:
In[5]:= | ![]() |
Out[5]= | ![]() |
If only one value meets the criterion, then no change is made:
In[6]:= | ![]() |
Out[6]= | ![]() |
Use a different name for the replacement key:
In[7]:= | ![]() |
Out[8]= | ![]() |
When multiple associations are provided the common categorization and order is established using Merge and a function provided by Method. Individual associations may have more or less in the "Other" category than the target scale. By default the Mean value of each key is used:
In[9]:= | ![]() |
Out[9]= | ![]() |
Using Method → First uses the first available value (IE from the first Association, unless keys are missing) is used to determine the ordering:
In[10]:= | ![]() |
Out[10]= | ![]() |
Method also accepts an integer and uses the nth Association to control the ordering:
In[11]:= | ![]() |
Out[11]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License