1
$\begingroup$

I would consider myself transitioning from beginner to intermediate skill in Mathematica, and am finally exploring Associations and Datasets. I am using version 12.

I have a Dataset (list of associations) I would like to Append another list of associations to this Dataset like so:

    dataset1 = Dataset[{<|a -> 11, b -> 12, c -> 13|>,<|a -> 21, b -> 22, c -> 22|> }]
    listAssocs = {<|m -> 31, n -> 32, p -> 33|>,<|m -> 41, n -> 42, p -> 43|>}

idealDataset=Dataset[{<|a -> 11, b -> 12, c -> 13,m -> 31, n -> 32, p -> 33|>,<|a -> 21, b -> 22, c -> 22,m -> 41, n -> 42, p -> 43|> }]

I have tried the following from the documentation and other answers:

dataset1[All, # ~Join~ listAssocs &]  (*obviously this would map the entire List of listAssocs to each row, but I tried*)

Map[dataset1[All, # ~Join~ #2 &],listAssocs] (*somehow simultaneously map each row of dataset1 to # and listAssocs to #2 and then join them??? *)

MapThread[Join,{dataset1,listAssocs}]

So far I have had to workaroud via unpacking like so:

MapThread[Join, {dataset1// Normal, listAssocs}]
$\endgroup$
4
  • $\begingroup$ Join[dataset1, Dataset@listAssocs]? $\endgroup$
    – kglr
    Jan 9, 2020 at 8:07
  • $\begingroup$ Thank you, however this just adds listAssocs as additional rows of dataset1 $\endgroup$ Jan 9, 2020 at 8:14
  • 3
    $\begingroup$ Join[dataset1, Dataset@listAssocs, 2] ought to do it. Or dataset1[MapThread[Join, {#, listAssocs}] &]. $\endgroup$
    – WReach
    Jan 9, 2020 at 15:58
  • $\begingroup$ Thank you, that worked. I looked at the linked answer already but I guess the shorthand notation confused me. $\endgroup$ Jan 10, 2020 at 5:27

0

Browse other questions tagged or ask your own question.