regroup#

swordfish.function.regroup()#

Group the data of a matrix based on user-specified column/row labels and apply aggregation on each group.

regroup is similar to the SQL keyword “group by”, except that “group by” is applied only on tables whereas this function is applied on matrices.

Note

It is recommended that the func parameter be specified as a built-in aggregate function as built-in functions are optimized internally for optimal performance.

Parameters:
  • X (Constant) – A matrix.

  • label (Constant) – A vector indicating the column/row labels based on which the matrix is grouped and aggregated. When byRow = true, the length of label must match the number of rows of X. Otherwise, it must match the number of columns of X.

  • func (Constant) – A unary aggregate function called on each group of the matrix. It can be built-in or user-defined.

  • byRow (Constant, optional) – A Boolean. The default value is true, indicating that the matrix will be grouped and aggregated by rows. False means to group and aggregate matrix by columns.