Learn R Programming

ChemoSpec (version 3.0-1)

avgFacLvls: Average levels of a factor in a data matrix

Description

avgFacLvls takes a matrix and calculates the column means for each level of each factor given. It then replaces the original matrix rows with the means corresponding to the factor/level memership of a particular sample (row).

Usage

avgFacLvls(matrix, fac)

Arguments

matrix
A matrix.
fac
A vector of character strings with length = nrow(matrix)

Value

  • A matrix whose rows are composed of the column means for each level of the factor.

References

https://github.com/bryanhanson/ChemoSpec

See Also

aovPCA for full details.

Examples

Run this code
M1 <- matrix(rnorm(100), nrow = 20, byrow = TRUE)
facs <- factor(c(rep("A",5), rep("B",5), rep("C", 5), rep("D", 5)))
M2 <- avgFacLvls(M1, fac = facs)

Run the code above in your browser using DataLab