Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Group rows in data by key values and summarize the remaining keys with a merging operator
ResourceFunction["GroupMerge"][data, key→g, …] groups the data according to function g and stores the results in column key. | |
ResourceFunction["GroupMerge"][data, {spec1,spec2,…}, …] combines multiple simultaneous groupings. | |
ResourceFunction["GroupMerge"][data, spec, {lbl1→f1,lbl2→f2,…}] adds new columns lbli to the data obtained by applying fi to the groups. | |
ResourceFunction["GroupMerge"][key, f] represents an operator form of ResourceFunction["GroupMerge"] that can be applied to an expression. |
Perform a simple group merge:
| In[1]:= | ![]() |
| Out[1]= |
Create a new dataset with rows corresponding to the unique values of the "a" column:
| In[2]:= | ![]() |
| In[3]:= | ![]() |
| Out[3]= |
Count the number of rows for each value of "a"
| In[4]:= | ![]() |
| Out[4]= |
Combine merged rows and counts:
| In[5]:= | ![]() |
| Out[5]= |
| In[6]:= | ![]() |
| Out[6]= |
Summarize data in the Titanic example Dataset:
| In[7]:= |
Group by gender, class and take the mean of the ages:
| In[8]:= | ![]() |
| Out[8]= | ![]() |
Group by an arbitrary grouping function:
| In[9]:= | ![]() |
| Out[9]= | ![]() |
Any function that outputs an Association can be used in the 3rd argument:
| In[10]:= | ![]() |
| Out[10]= | ![]() |
GroupMerge can also be used as an operator:
| In[11]:= | ![]() |
| Out[11]= | ![]() |
The Automatic merging function is equivalent to:
| In[12]:= | ![]() |
| In[13]:= | ![]() |
| Out[13]= |
| In[14]:= | ![]() |
| Out[14]= |
Use the resource function MergeByKey to summarize different columns in different ways:
| In[15]:= | ![]() |
| Out[15]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License