Wolfram 语言与系统 10.0 (2014)|旧版文档

此为更早版本的 Wolfram 语言文档查看最新文档(版本11.2)

GroupBy

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

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

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.

更多信息更多信息

  • GroupBy provides a generalization of the map reduce operation.
  • GroupBy[spec][expr] is equivalent to GroupBy[expr,spec].

范例范例打开所有单元关闭所有单元

基本范例  (10)基本范例  (10)

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

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

Group pairs of items according to the last element:

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

Group last parts of pairs according to the first part:

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

Use a symbolic selector for grouping:

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

Pairs for which the selector yields the same value are grouped under the same key:

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

Use different functions to extract keys and values:

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

Use the operator form of Extract to specify the key or the value:

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

Use a combiner function to combine the values:

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

Group associations according to the value of their first element:

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

Group associations according to the value of the given key:

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

Specify keys and values using Key:

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

Missing keys are replaced with Missing:

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

Use the operator form of GroupBy:

In[1]:=
Click for copyable input
Out[1]=
2014年引入
(10.0)