Group-wise sum of a matrix along one axis
sumGroups.RdFor each unique value of the grouping vector y, sums the
corresponding rows (or columns) of X. Used internally by
wilcoxauc() and collapse_counts(), but exposed as a fast
group-wise reduction primitive that works on both dense matrices
and dgCMatrix sparse inputs.
Usage
sumGroups(X, y, MARGIN = 2)
# S3 method for class 'dgCMatrix'
sumGroups(X, y, MARGIN = 2)
# S3 method for class 'matrix'
sumGroups(X, y, MARGIN = 2)Arguments
- X
Numeric matrix or
dgCMatrix.- y
Group label vector. Coerced to integer factor codes.
- MARGIN
Whether observations are along rows or columns of
X.MARGIN = 2(default): observations are rows (length(y) == nrow(X)); rows are summed within each group.MARGIN = 1: observations are columns (length(y) == ncol(X)); columns are summed within each group.
Value
Numeric matrix of shape n_groups x n_features. Row order
matches the integer order of factor(y).