Let's say I have the following nested dataset:
SeedRandom[14];
data=Transpose@Dataset@AssociationThread[{"a","b"},RandomInteger[{0,20},{2,50}]];
data=data[All,<|#,"combine"-><|"c"->Slot@"a"*2,"d"->Slot@"a"-Slot@"b"|>|>&]
I want to selectively apply a function, say f
, onto the nested column c
and keep the structure of the original dataset. Currently, I used the following to do it.
Dataset[Transpose[ (Transpose@data)[<|#, "combine" -> Normal@data[All, "combine", {"c" -> f}]|> &] ] , MaxItems -> 5]
I found in the Dataset
doc that dataset[All,{n->f}]
can selectively map f onto the n^th column
, which worked for col b
.
Dataset[data[All, {"b" -> f}], MaxItems -> 5]
However, when I applied the following. Only the innermost subdataset was updated/returned.
Dataset[data[All, "combine", {"c" -> f}], MaxItems -> 5]
Is it possible to correct this? I also wonder is there any other way to return what I wanted. Thanks.
MapAt[f, data, {All, 3, 1}]
? $\endgroup$MapAt[f, data, {All, "combine", "c"}]
to better suit my data. $\endgroup$