1
$\begingroup$

Let's assume I created the following dataset:

Dataset[{<|"x" -> a1, "y" -> b1, "z" -> c1|>, <|"x" -> a2, "y" -> b2, 
   "z" -> c2|>, <|"x" -> a3, "y" -> b3, "z" -> c3|>}]

enter image description here

So if I have 3 list of parameters:

a = {a1, a2, a3};
b = {b1, b2, b3};
c = {c1, c2, c3};

How can I generate automatic Dataset using slots and pure functions without writing each association explicitly.

I have tried somthing like:

dataset = 
 Dataset[{<|"x" -> #1, "y" -> #2, "z" -> #3|> & @@ {a, b, c}}]

but the output is not what I wanted it to be:

enter image description here

Any ideas, or other solutions to create dataset from the given lists??

Thanks!

$\endgroup$
  • 1
    $\begingroup$ For such a small set you can do Dataset[AssociationThread[{"x", "y", "z"} -> #] & /@ Transpose[{a, b, c}]]. $\endgroup$ – b.gates.you.know.what Jun 6 at 9:02
2
$\begingroup$

Try this:

Dataset@MapThread[<|"x" -> #1, "y" -> #2, "z" -> #3|> &, {a, b, c}]
$\endgroup$
0
$\begingroup$

This works too:

{"x", "y", "z"} -> {a, b, c} // Thread // Map[Thread] // Transpose // 
  Map[Association] // Dataset
$\endgroup$

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.