colsum {DelayedMatrixStats} | R Documentation |
Compute column and row sums across rows or columns of a numeric matrix-like object for each level of a grouping variable.
NOTE: This man page is for the colsum()
and rowsum()
S4 generic functions defined in the DelayedMatrixStats package. See
base::rowsum()
for the default method of rowsum()
(defined in the
base) package. The colsum()
generic is the natural extension of
rowsum()
but has no equivalent in the base package.
Bioconductor packages can define specific methods for objects (typically
matrix-like) not supported by the default method.
colsum(x, group, reorder = TRUE, ...) rowsum(x, group, reorder = TRUE, ...) ## S4 method for signature 'ANY' colsum(x, group, reorder = TRUE, na.rm = FALSE, ...)
x |
A matrix-like object. Missing values are allowed. A numeric vector will be treated as a column vector. |
group |
A vector or factor giving the grouping, with one element per
row of |
reorder |
If |
... |
Additional arguments passed to specific methods. |
na.rm |
logical ( |
The default is for rowsum()
(resp. colsum()
) to reorder the rows
(columns) to agree with base::tapply()
as in the example below.
Reordering should not add noticeably to the time except when there are very
many distinct values of group
and x
has few columns (rows).
To sum over all the rows (columns) of a matrix (i.e. a single group) use
colSums()
(rowSums()
), which should be even faster. To sum over a
subset of rows and/or columns of a matrix (i.e. a subset of a single group)
use colSums2()
(rowSums2()
).
A matrix-like object containing the sums. For rowsum()
, there will
be one row per unique value of group
. For colsum()
, there will be one
column per unique value of group
.
See base::rowsum()
for the value returned by the default rowsum()
method.
Specific methods defined in Bioconductor packages will typically return an object of the same class as the input object.
base::rowsum()
for the default rowsum()
method.
methods::showMethods()
for displaying a summary of the methods defined for a given generic function.
methods::selectMethod()
for getting the definition of a specific method.
rowsum showMethods("rowsum") selectMethod("rowsum", "ANY") # the default method