Compute column sums across rows of a numeric matrix-like object for
each level of a grouping variable.
rowsum is generic, with a
method for data frames and a default method for vectors and matrices.
1 2 3 4 5 6 7
a matrix, data frame or vector of numeric data. Missing values are allowed. A numeric vector will be treated as a column vector.
a vector or factor giving the grouping, with one element
per row of
other arguments to be passed to or from methods
The default is to reorder the rows to agree with
tapply as in
the example below. Reordering should not add noticeably to the time
except when there are very many distinct values of
x has few columns.
The original function was written by Terry Therneau, but this is a new implementation using hashing that is much faster for large matrices.
To sum over all the rows of a matrix (ie, a single
colSums, which should be even faster.
For integer arguments, over/underflow in forming the sum results in
A matrix or data frame containing the sums. There will be one row per
unique value of
1 2 3 4 5 6 7 8 9
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.