Merge

Merge[{assoc1,assoc2,},f]
merges the associations , using the function f to combine values with the same key.

Merge[{key1val1,key2val2,},f]
gives an association in which values corresponding to identical keys are combined using f.

Merge[f]
represents an operator form of Merge that can be applied to an expression.

DetailsDetails

  • Merge can operate on any combination of associations and lists of rules.
  • In Merge[expr,f], the function f is applied to lists of values that share the same key.
  • Merge[f][expr] is equivalent to Merge[expr,f].

ExamplesExamplesopen allclose all

Basic Examples  (4)Basic Examples  (4)

Merge two associations, using Total to combine elements with the same key:

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

Return values with distinct keys in lists:

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

Combine rules with the same left-hand side:

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

Create a Merge operator:

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