statList provides a general method for calculating univariate or multivariate statistics for a matrix or data.frame stratified by one or more factors.
statList(X, factors, FUN, drop =FALSE,...)
Arguments
X: A matrix or data frame containing the variables to be summarized
factors: A vector, matrix or data frame containing the factors for which X is to be summarized. If factors is not specified, the result is calculated for all of the data in X.
FUN: A function to be applied to the pieces of X, as split by factors.
drop: Logical, indicating whether empty levels of factors are to be dropped from the result.
...: Other arguments, passed to FUN.
Returns
Returns a list of items corresponding to the unique elements in factors, or the interaction of factors. Each item is the result of applying FUN to that collection of rows of X. The items are named according to the levels in factors.
Details
statList is the general function. X is first split by factors, and FUN is applied to the result.
colMeansList and covList are just calls to statList
with the appropriate FUN.
Examples
# grand meansstatList(iris[,1:4], FUN=colMeans)# species meansstatList(iris[,1:4], iris$Species, FUN=colMeans)# samecolMeansList(iris[,1:4], iris$Species)# var-cov matrices, by speciescovList(iris[,1:4], iris$Species)# multiple factorsiris$Dummy <- sample(c("Hi","Lo"),150, replace=TRUE)colMeansList(iris[,1:4], iris[,5:6])