applyByCategory {Category} | R Documentation |
For each category, apply the function FUN
to the set of values
of stats
belonging to that category.
applyByCategory(stats, Amat, FUN = mean, ...)
stats |
Numeric vector with test statistics of interest. |
Amat |
Either a logical matrix or an
lgCMatrix-class : the adjacency matrix of the
bipartite genes - category graph.
Its rows correspond to the categories, columns
to the genes, and TRUE indicates membership.
The columns are assumed to be aligned with the elements of stats . |
FUN |
A function to apply to the subsets stats by
categories. |
... |
Extra parameters passed to FUN . |
For GO categories, the function cateGOry
might be useful
for the construction of Amat
.
The return value is a list or vector of length equal to
the number of categories. Each element corresponds to the
values obtained by applying FUN
to the subset of values
in stats
according to the category defined for that
row.
R. Gentleman, contributions from W. Huber
set.seed(0xabcd) st = rnorm(20) a = matrix(sample(c(FALSE, TRUE), 60, replace=TRUE), nrow=3) rownames(a) = paste("category", 1:3, sep="") colnames(a) = names(st) = paste("g", 1:20, sep="") sa = Matrix(a) ## sparse k1 = applyByCategory(st, a, median) k2 = applyByCategory(st, sa, median) stopifnot(identical(k2, k1))