rowsum
Group Row Sums of a Matrix

Description

Computes sums across rows of a matrix for each level of a grouping variable.

Usage

rowsum(x, group, reorder = TRUE, ...)
rowsum.default(x, group, reorder = TRUE, na.rm = FALSE, ...)

Arguments

x a matrix or a vector of numeric data. Missing values are allowed.
group a vector giving the grouping, with one element per row of x. Missing values are not allowed.
reorder a logical value. If TRUE (the default), the result is in the order of sort(unique(group)). If FALSE, it is in the order that rows are encountered (therefore might run faster for large matrices).
na.rm a logical flag. If TRUE, indicates that missing values should be removed before computations. The default is FALSE.
... additional optional arguments.
Value
returns a matrix containing the sums. The matrix has one row per unique value of group and the same number of columns as x.
See Also
tapply.
Examples
x <- matrix(1:20, ncol=5)
group <- sample(1:4, 4, T)
rowsum(x, group)
Package base version 6.1.4-13
Package Index