average: Average select columns of matrix together.

Description Usage Arguments Value Examples

View source: R/average.R

Description

Given an N by P matrix M, where each column p in 1, ..., P belongs to a group g of G total groups, this function computes the mean column vector per group.

Usage

1
average(M, g)

Arguments

M

numeric matrix

g

(character) vector that indicates groups of columns of M

Value

An N by G matrix M_bar

Examples

1
2
3
4
5
M <- diag(6)
g <- rep(letters[1:2], 3)
length(g) == ncol(M)
M_bar <- average(M, g)
ncol(M_bar) == length(unique(g))

mcfreund/mfutils documentation built on Feb. 6, 2022, 4:57 a.m.