Is there a general Transpose
for Dataset
/Association
that will transpose arbitrary levels, such as
Transpose[array, perm]
which will permute the levels of array
according to the permutation perm
? One seems to be able to use Transpose[ds]
to transpose levels 1 and 2 and Map[Query@Transpose, ds, {n}]
to transpose levels n+1
and n+2
. But they only work on "adjacent" levels. To transpose levels 1 and 3 (i.e. perm = {3, 2, 1}
), I seem to have to do something like the following
Transpose[Transpose /@ Transpose@ assoc]
Transpose[ds][Transpose, Transpose]
Is there a general way to do this for an arbitrary permutation of the levels of the data?
(I give a solution below, but as I'm learning how to use Dataset
, I figure there are better ways.)
Related: Association of Associations : how to permute level 1 and level 2 keys? and comments.
Comments
Post a Comment