# Rearranging a Dataset

When processing a larger Dataset I came up do a point where I want to form a dataset with culumn heads from an intermediate structure. Here is an example of this structure:

test = {<|"name" -> "alpha",
"group" -> "one"|> -> {<|"value" -> 459|>}, <|"name" -> "beta",
"group" -> "two"|> -> {<|"value" -> -338|>}, <|"name" -> "gamma",
"group" -> "two"|> -> {<|"value" -> 363|>}};


making a dataset:

assoc = Association@test; Dataset@assoc


this gives:

Now I´m searching a way to make this a dataset with column-heads "name", "group" and "value". Maybe I´m blind for a moment, but I could not manage it??? Can anyone give me a hint?

test = {<|"name" -> "alpha", "group" -> "one"|> -> {<|"value" -> 459|>},
<|"name" -> "beta", "group" -> "two"|> -> {<|"value" -> -338|>},
<|"name" -> "gamma", "group" -> "two"|> -> {<|"value" -> 363|>}};

Association /@ Flatten /@ Normal[test /. Rule -> List] // Dataset


• Thanks a lot! I´ve simply overseen the step /.Rule->List...o.l. sometimes one does no see the obvious – mgamer Dec 7 '14 at 14:31

If we assume that we are starting from the exhibited dataset:

dataset = Dataset@assoc;


... then we can reshape it like this:

dataset[All, Apply@Association]


Or, equivalently:

dataset[Map[Apply@Association]]


This will also do the trick, although it is a little messy since MapThread presently lacks an operator form:

dataset[{Keys, Values}][MapThread[Association, #]&]


Edit

And here is yet another way:

dataset[All, <| Keys@#, Values@# |> &]

Dataset[Join@@@({#,Join@@#2}&@@@test)]
(* or  Dataset[Join@@@({#,Sequence@@#2}&@@@test)] *)


• Must be a record for @@@ density. – alancalvitti Jan 8 '15 at 18:11