apoc.coll.frequencies

Function APOC Core

apoc.coll.frequencies(coll) - returns a list of frequencies of the items in the collection, keyed by item and count (e.g., [{item: xyz, count:2}, {item:zyx, count:5}, {item:abc, count:1}])

Signature

apoc.coll.frequencies(coll :: LIST? OF ANY?) :: (LIST? OF ANY?)

Input parameters

Name Type Default

coll

LIST? OF ANY?

null

Usage Examples

The following returns a list of maps containing each item and their frequency in a collection:

RETURN apoc.coll.frequencies([1,3,5,7,9,9]) AS output;
Table 1. Results
Output
[
    {
      "count": 1,
      "item": 1
    }
    ,
    {
      "count": 1,
      "item": 3
    }
    ,
    {
      "count": 1,
      "item": 5
    }
    ,
    {
      "count": 1,
      "item": 7
    }
    ,
    {
      "count": 2,
      "item": 9
    }
]