Join lists by observing x-value
A couple of ways:
ds = Dataset1~Join~Dataset2
List @@@ Normal[GroupBy[ds, First -> Last]]
Last@Reap[Sow[#2, #1] & @@@ ds, _, List]
All yield:
{{20, {1}}, {30, {1.3, 1.2}}, {40, {0.4, 1}}, {50, {0.9,
0.4}}, {80, {1}}, {90, {1}}}
or
d1 = Rule @@@ Dataset1
d2 = Rule @@@ Dataset2
List @@@ Normal[Merge[{d1, d2}, Join]]
One way is to use GatherBy
and then coerce the resulting list into the form you require:
d1 = {{20, 1}, {30, 1.3}, {40, 0.4}, {50, 0.9}};
d2 = {{30, 1.2}, {40, 1}, {50, 0.4}, {80, 1}, {90, 1}};
{#[[1, 1]], #[[All, 2]]} & /@ GatherBy[Join[d1, d2], First]
{{20, {1}}, {30, {1.3, 1.2}}, {40, {0.4, 1}}, {50, {0.9, 0.4}}, {80, {1}}, {90, {1}}}
A different way:
d = GatherBy[Dataset1~Join~Dataset2, First]
{Max[#1], #2} & @@@ Transpose /@ d
{{20, {1}}, {30, {1.3, 1.2}}, {40, {0.4, 1}}, {50, {0.9, 0.4}}, {80, {1}}, {90, {1}}}