row_mean_aggregate: Row/Column Means/Variances by Factor

Description Usage Arguments Details Value Examples

View source: R/General.R

Description

Efficiently calculates the row means or row variances or column means or columns variances of a matrix split by a factor.

Usage

1
2
3
4
	row_mean_aggregate(mat, groups)
	row_var_aggregate(mat, groups)
	col_mean_aggregate(mat, groups)
	col_var_aggregate(mat, groups)

Arguments

mat

a matrix

groups

a factor of length ncol(mat) to split the matrix by.

Details

Calculates the row[column] means[variances] for columns belonging to each level of the provided groups. Uses an approach much more efficient than aggregate. Requires at least 2 samples from each group.

Value

a matrix of dimension nrow(mat) x length(levels(groups)) of means[variances] for each row for each group. a matrix of dimension ncol(mat) x length(levels(groups)) of means[variances] for each column for each group.

Examples

1
2
3
4
5
6
7
	groups <- c("A", "A", "B", "B", "C","C","C")
	vals <- matrix(rnorm(70), ncol=7)
	group_means = row_mean_aggregate(vals, groups)
	group_vars = row_var_aggregate(vals, groups)
	vals <- t(vals)
	group_means = col_mean_aggregate(vals, groups)
	group_vars = col_var_aggregate(vals, groups)

tallulandrews/TreeOfCells documentation built on April 26, 2020, 2:43 p.m.