Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Transpose the levels of an Association with nested levels
ResourceFunction["AssociationTranspose"][assoc] transposes the first two levels in assoc. | |
ResourceFunction["AssociationTranspose"][assoc,{n1,n2,…}] transposes assoc so that the kth level in assoc is the nkth level in the result. | |
ResourceFunction["AssociationTranspose"][assoc,m<->n] transposes levels m and n in assoc, leaving all other levels unchanged. |
Create a nested Association with three levels:
In[2]:= | ![]() |
Out[2]= | ![]() |
Transpose an Association of three levels using different permutations:
In[3]:= | ![]() |
In[4]:= | ![]() |
Out[4]= | ![]() |
In[5]:= | ![]() |
Out[5]= | ![]() |
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
Exchange levels 1 and 3 of an Association of three levels using TwoWayRule to express a permutation:
In[8]:= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
An invalid permutation specification causes an error:
In[10]:= | ![]() |
Out[10]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License