4
$\begingroup$

I have a problem, which I assume to be trivial, but can't solve it:

I have two datasets,

ds = Dataset@* Map[AssociationThread[{"ID", "Date", "A"} -> #] &]@{ {"C9", SQLDateTime[{2012, 12, 11, 0, 0, 0.}], 10}, {"C9", SQLDateTime[{2015, 2, 19, 19, 30, 0.}], 9}, {"C9", SQLDateTime[{2013, 1, 22, 0, 0, 0.}], 12}, {"C10", SQLDateTime[{2013, 1, 28, 9, 25, 0.}], 15}, {"C10", SQLDateTime[{2014, 3, 21, 20, 0, 0.}], 12}, {"C11", SQLDateTime[{2013, 8, 27, 6, 40, 0.}], 8}}

and

ds2 = Dataset@* Map[AssociationThread[{"ID", "Date", "B"} -> #] &]@{ {"C09", SQLDateTime[{2012, 12, 15, 1, 0, 0.}], 221}, {"C09", SQLDateTime[{2014, 1, 20, 0, 30, 0.}], 112}, {"C10", SQLDateTime[{2013, 1, 28, 0, 25, 0.}], 315}, {"C11", SQLDateTime[{2014, 3, 2, 6, 40, 0.}], 128}}

which I want to combine to one, which looks like that in the end:

resulting dataset

So the rows are only written below each other and in the columns, where no value is available a placeholder is used.

The problem is, I don't know how to obtain, this result. Is it any specific use of JoinAcross or do I have to take the Join function or even something else?

Every hint is welcome.

$\endgroup$
6
$\begingroup$
SortBy["ID"]@JoinAcross[ds,ds2, {"ID", "Date"}, "Outer"]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks a lot! I didn't use two arguments in the JoinAcross (but only the "ID") and got therefore puzzling results. $\endgroup$ – Lea Sep 28 '17 at 18:36
  • $\begingroup$ @Lea, my pleasure. Thank you for the accept. $\endgroup$ – kglr Sep 28 '17 at 18:48
  • $\begingroup$ I just stumbled about one question concerning your answer, which fits my purpose well. But I don't understand why it works, since in the JoinAcross docu it is mentioned: JoinAcross[{a1,a2,…},{b1,b2,…},{key1,key2,…}] joins pairs of associations only when the values associated with all keys keyi are the same. But the dates in the upper example are NOT the same. Can you help me to understand your solution? $\endgroup$ – Lea Nov 15 '17 at 13:08
  • $\begingroup$ @Lea, please see JoinAcross >> Details and Options for details of how the four-argument form (JoinAcross[alist, blist, spec, "jspec"]) works: $\endgroup$ – kglr Nov 15 '17 at 17:49

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.