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:

enter image description here

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


  • $\begingroup$ Thanks a lot! I´ve simply overseen the step /.Rule->List...o.l. sometimes one does no see the obvious $\endgroup$ – 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 screenshot

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

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


And here is yet another way:

dataset[All, <| Keys@#, Values@# |> &]
(* or  Dataset[Join@@@({#,Sequence@@#2}&@@@test)] *)

enter image description here

  • 1
    $\begingroup$ Must be a record for @@@ density. $\endgroup$ – alancalvitti Jan 8 '15 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.