Function Repository Resource:

# KeyCombine

Map a function over the keys of an association, and collect or combine values in the event of key collisions

Contributed by: Szabolcs Horvát
 ResourceFunction["KeyCombine"][f,assoc] maps f over the keys in assoc and collects values having the same key into a list. ResourceFunction["KeyCombine"][f,assoc,comb] uses the combiner function comb to combine values having the same key. ResourceFunction["KeyCombine"][f] represents an operator form of ResourceFunction["KeyCombine"] that can be applied to an expression.

## Details and Options

ResourceFunction["KeyCombine"] works analogously to KeyMap, but it combines values instead of discarding them in the event of key collisions.

## Examples

### Basic Examples (2)

Sort the keys of an association and collect values that end up having the same key:

 In[1]:=
 Out[1]=

Sum values instead of collecting them:

 In[2]:=
 Out[2]=

### Applications (2)

Convert frequency data (counts) created using a bin size of 1 to a bin size of 3:

 In[3]:=
 Out[3]=
 In[4]:=
 Out[4]=

Combine reciprocal edges of a weighted, directed graph using geometric mean:

 In[5]:=
 In[6]:=
 Out[6]=
 In[7]:=
 Out[7]=

### Properties and Relations (1)

KeyCombine does not change the ordering of keys:

 In[8]:=
 Out[8]=

Szabolcs Horvat

## Version History

• 2.0.0 – 09 August 2019
• 1.0.0 – 15 July 2019

## Author Notes

Thank you to Kuba Podkalicki for help with the implementation (see External Links).