aggrMatrix {mcmcsae}R Documentation

Utility function to construct a sparse aggregation matrix from a factor

Description

Utility function to construct a sparse aggregation matrix from a factor

Usage

aggrMatrix(fac, w = 1, mean = FALSE, facnames = FALSE)

Arguments

fac

factor variable.

w

vector of weights associated with the levels of fac.

mean

if TRUE, aggregation will produce (weighted) means instead of sums.

facnames

whether the factor levels should be used as column names for the aggregation matrix.

Value

A sparse aggregation matrix of class tabMatrix.

Examples

n <- 1000
f <- sample(1:100, n, replace=TRUE)
x <- runif(n)
M <- aggrMatrix(f)
all.equal(crossprod_mv(M, x), as.vector(tapply(x, f, sum)))


[Package mcmcsae version 0.7.7 Index]