aggrMatrix | R Documentation |
Utility function to construct a sparse aggregation matrix from a factor
aggrMatrix(fac, w = 1, mean = FALSE, facnames = FALSE)
fac |
factor variable. |
w |
vector of weights associated with the levels of |
mean |
if |
facnames |
whether the factor levels should be used as column names for the aggregation matrix. |
A sparse aggregation matrix of class tabMatrix
.
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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.