I have two associations like this
In[211]:= assoc1 =
AssociationThread[{a, b, c, d, e, f, g}, {1, 2, 3, 4, 5, 6, 7}]
Out[211]= <|a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7|>
In[212]:= assoc2 =
AssociationThread[{a, b, c, d, f, g, h}, {12, 22, 23, 24, 25, 26, 27}]
Out[212]= <|a -> 12, b -> 22, c -> 23, d -> 24, f -> 25, g -> 26,
h -> 27|>
Now when i want to merge them by using Identity
In[213]:= Merge[{assoc1, assoc2}, Identity]
Out[213]= <|a -> {1, 12}, b -> {2, 22}, c -> {3, 23}, d -> {4, 24},
e -> {5}, f -> {6, 25}, g -> {7, 26}, h -> {27}|>
So here is the point: I want to obtain a value of "0" for the missing values of each association AND in the position according to the ordering of the associations (in this example for key e
{5,0}
and for key h
{0,27}
since e
is missing in assoc2
and h
is missing in assoc1
)
However I found a solution by first using a combination of Complement
, Union
and Intersection
to obtain a sample of the unique keys within each association. Then I gave them a value of zero and merged them with each assoc by using Total
. Finally I merged them again with Identity
and obtained the desired result but that is far away from being an elegant solution....
Join
is better accomplished withKeyUnion
. $\endgroup$