aggMatrix: Aggregate Values Accross Rows of a Matrix

Description Usage Arguments Value See Also Examples

Description

Apply a function columnwise to groups of rows in a matrix, according to a grouping index. Essentially applies the same tapply to multiple colums of a matrix.

Usage

1
aggMatrix(x, index, fun = sum, margin = 1, ...)

Arguments

x

a matrix containing numeric, complex, integer or logical values, or a data frame.

index

list of one or more factors, each of same length as dim(x)[1] (as in tapply). The elements are coerced to factors by as.factor.

fun

the function to be applied. In the case of functions like +, %*%, etc., the function name must be backquoted or quoted.

margin

over which margin should the operation take place (i.e. which margin matches index).

...

other arguments to be passed to fun.

Value

a matrix with dimensions dim(x)[1], length(index)

See Also

Other utility: badRows, cellIdx, expand, merge.formula, rowProds

Examples

1
2
x <- expand(rnorm(5), 3)
aggMatrix(x, c(1, 1, 1, 2, 2))

SEEG-Oxford/seegMBG documentation built on May 9, 2019, 11:08 a.m.