I would like to join associations in the following way. Say I have a dataset d1:

keys1 = {"first", "last", "age"};
first = {"Mike", "Carl", "Tina"};
last = {"Shulz", "Miller", "Ruben"};
age = {28, 35, 34};


d1 = Dataset[
  AssociationThread[keys1, #] & /@ ({first, last, age}\[Transpose])]

and a second dataset

names = d1[All, {"first", "last"}][All, #first ~~ " " ~~ #last &] // 
(*{"Mike Shulz", "Carl Miller", "Tina Ruben"} *)


income = {30000, 23000, 40000}

so the dataset d2 is

d2 = Dataset[
  AssociationThread[{"fullname", "income"}, #] & /@ ({names, 

Then I would like to combine (join) these datasets on the full name of a person, which is present in the second dataset but not in the first. Something like

 Normal@d2, (Key["first"] ~~ Key["last"]) -> Key["fullname"]]

(clearly) does not work. Is there an easy way to achieve the desired result (without modifying the first dataset and append a full name on it)?


Besides the question is answered by a good workaround another questions arises: "Why the coloring"? I tried the solution from WReach - works fine, but I get parts of the answer colored and do not know why... Can someone help (again)?... Sorry, I just saw it: missing braces {}....

enter image description here


2 Answers 2


Unfortunately, JoinAcross does not presently (V11.1) support any form of computed key specification. We have no choice but to adjust the first dataset to include the full name.

We do not necessarily have to go so far as to destructively alter d1 -- we can add the computed column in an inline query:

  d1[All, <| "fullname"-> #first~~" "~~#last, # |> &] // Normal
, d2 // Normal
, Key["fullname"] -> Key["fullname"]
] // Dataset

dataset screenshot

As an aside, in later versions of Mathematica we can usually omit the applications of Normal, Key and Dataset:

  d1[All, <| "fullname"-> #first~~" "~~#last, # |> &]
, d2
, "fullname" -> "fullname"

... but be prepared to add them back in since JoinAcross has been very finicky across releases (especially when applied to datasets).

  • $\begingroup$ Thank you for the fast answer, so I´m going to take this as a (quite good) workaround $\endgroup$
    – mgamer
    May 30, 2017 at 5:28


keys1 = {"first", "last", "age"};
first = {"Mike", "Carl", "Tina"};
last = {"Shulz", "Miller", "Ruben"};
age = {28, 35, 34};
d1 = Dataset[AssociationThread[keys1, #] & /@ ({first, last, age}\[Transpose])]

fullname[person_] := "fullname" -> person["first"] <> " " <> person["last"]
addFullname[person_] := Prepend[person, fullname@person]
addFullnames[persons_] := persons // Normal // Map[addFullname] // Dataset

Out: enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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