KeyUnion

KeyUnion[{assoc1,assoc2,}]
generates a list of associations in which each association has the union of the keys of the , padding by inserting values of Missing[] if necessary.

KeyUnion[{assoc1,assoc2,},f]
uses as the value associated with a missing key.

DetailsDetails

  • KeyUnion returns a list of associations in which all the associations have keys ordered in the same way.
  • If f is an association containing all the keys to be returned by KeyUnion, then the order of keys in f will determine the order of keys in the associations returned.
  • In other cases, the keys will appear in order of their first occurrence in the sequence of .
  • KeyUnion can be used not only on Association objects, but also on lists of rules.

ExamplesExamplesopen allclose all

Basic Examples  (4)Basic Examples  (4)

Make a list of associations with the same keys:

In[1]:=
Click for copyable input
Out[1]=

Reorder the keys of all associations:

In[1]:=
Click for copyable input
Out[1]=

Use a function to provide missing values:

In[1]:=
Click for copyable input
Out[1]=

The missing function can be an association:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 2014
(10.0)