Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Apply a function to keys of an Association and group results by modified keys
ResourceFunction["KeyGroupBy"][<|k1→v1,k2→v2,…|>,f] gives an association that groups the ki→vi associations with distinct keys f[ki]. | |
ResourceFunction["KeyGroupBy"][<|k1→v1,k2→v2,…|>,{fs1,fs2,…}] groups into nested associations using fsi at level i. | |
ResourceFunction["KeyGroupBy"][<|k1→v1,k2→v2,…|>,spec,red] applies the function red to reduce sub-associations that are generated. | |
ResourceFunction["KeyGroupBy"][spec] represents an operator form of that ResourceFunction["KeyGroupBy"] can be applied to an association. |
Group keys by their leading letters:
In[1]:= |
Out[1]= |
Create an Association for testing:
In[2]:= |
Group the elements repeatedly by applying several functions onto their keys:
In[3]:= |
Out[3]= |
Group the elements repeatedly by applying several functions onto their keys and reduce the results into their means:
In[4]:= |
Out[4]= |
KeyGroupBy can be useful in reorganizing levels of a nested dataset in together with the resource function AssociationKeyFlatten:
In[5]:= |
Out[3]= |
In[6]:= |
Out[6]= |
This work is licensed under a Creative Commons Attribution 4.0 International License