GroupBy
GroupBy[{elem1,elem2,…},f]
gives an association that groups the elemi into lists associated with distinct keys f[elemi].
GroupBy[{elem1,elem2,…},fkfv]
groups the fv[elemi] according to the fk[elemi].
GroupBy[{elem1,elem2,…},{fs1,fs2,…}]
groups into nested associations using fsi at level i.
GroupBy[{elem1,elem2,…},spec,red]
applies the function red to reduce lists of values that are generated.
Details
- GroupBy provides a generalization of the map reduce operation.
- GroupBy[list,f] gives an association whose keys are the distinct f[elemi] and whose values are sublists of the list list.
- GroupBy[assoc,f] gives an association whose keys are the distinct f[elemi] and whose values are subassociations of the association assoc.
- GroupBy[spec][expr] is equivalent to GroupBy[expr,spec].
Examples
open allclose allBasic Examples (3)
Scope (12)
Group the elements repeatedly by using several functions:
Group last parts of pairs according to the first part:
Group values of an association by using several functions:
Use a symbolic selector for grouping:
Pairs for which the selector yields the same value are grouped under the same key:
Use different functions to extract keys and values:
Use the operator form of Extract to specify the key or the value:
Use a combiner function to combine the values:
Group associations according to the value of their first element:
Group associations according to the value of the given key:
Specify keys and values using Key:
Missing keys are replaced with Missing:
Group a list of integers by positivity and parity, displaying the groups as column vectors:
Use the operator form of GroupBy:
Group results of applying a function to values of an association:
Applications (1)
Use GroupBy to group rows in a dataset, introducing new levels of association:
Text
Wolfram Research (2014), GroupBy, Wolfram Language function, https://reference.wolfram.com/language/ref/GroupBy.html.
CMS
Wolfram Language. 2014. "GroupBy." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/GroupBy.html.
APA
Wolfram Language. (2014). GroupBy. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GroupBy.html