GroupBy

GroupBy[{elem1,elem2,},f]
gives an association that groups the into lists associated with distinct keys .

GroupBy[{elem1,elem2,},fkfv]
groups the according to the .

GroupBy[{elem1,elem2,},{fs1,fs2,}]]
groups into nested associations using at level i.

GroupBy[{elem1,elem2,},spec,red]
applies the function red to reduce lists of values that are generated.

GroupBy[spec]
represents an operator form of GroupBy that can be applied to an expression.

DetailsDetails

  • GroupBy provides a generalization of the map reduce operation.
  • GroupBy[list,f] gives an association whose keys are the distinct and whose values are sublists of the list list.
  • GroupBy[assoc,f] gives an association whose keys are the distinct and whose values are subassociations of the association assoc.
  • GroupBy[spec][expr] is equivalent to GroupBy[expr,spec].

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

Group pairs of items according to the first element of the pair:

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

Group values of an association:

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