Hi Folks, Not sure if this will format correctly, but. Mathematica newbie here. Given :
data = <|"on" -> <|"A" -> <|Length -> 19, Total -> 8|>,
"B" -> <|Length -> 19, Total -> 8|>,
"C" -> <|Length -> 7, Total -> 0|>|>,
"off" -> <|"A" -> <|Length -> 9, Total -> 42|>,
"B" -> <|Length -> 7, Total -> 11|>,
"C" -> <|Length -> 9, Total -> 27|>|>|>;
(*Extract the columns (A,B,C,...)*)
columns = Keys[data["on"]];
(*Extract the data for "on" and "off"*)
extractRowData[status_] :=
Map[Function[
column, {data[status][column][Length],
data[status][column][Total]}], columns];
(*Construct the dataset with hierarchical columns*)
finalDataset = Dataset[
Association[
"on" ->
AssociationThread[columns, extractRowData["on"]],
"off" ->
AssociationThread[columns, extractRowData["off"]]]][All,
AssociationThread["group",
Map[Function[column,
Association["Length" -> #[[1]],
"Total" -> #[[2]]]], #1] & /@ # &]]
The finalDataset duplicates the Length, Total values row such that there are two row for on/off where there should be only one row for on/off. Looking at the finalDataset via //Normal show that the Length,Total element bit is being duplicated, but I cannot track where this happens though I suspect something in my "&/@#&" bit but its confusing me presently. Any help much appreciated. Thanks