R: Average Levels of a Factor in a Data Matrix

avgFacLvls {ChemoSpec} | R Documentation

## 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.

### Author(s)

Matthew J. Keinsley and Bryan A. Hanson, DePauw University.

### References

https://github.com/bryanhanson/ChemoSpec

### See Also

`aov_pcaSpectra` for full details.

### Examples

    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)

[Package ChemoSpec version 4.4.97 Index]