Learn R Programming

wrMisc (version 1.15.3.1)

rowGrpMeans: rowMeans with destinction of groups (of columns, eg groups of replicates)

Description

rowGrpMeans calculates column-means for matrix with multiple groups of data, ie similar to rowMeans but one mean for each group of data. Groups are specified as columns of 'x' in 'grp' (so length of grp should match number of columns of 'x', NAs are allowed).

Usage

rowGrpMeans(x, grp, na.rm = TRUE)

Value

matrix with mean values

Arguments

x

matrix or data.frame

grp

(character or factor) defining which columns should be grouped (considered as replicates)

na.rm

(logical) a logical value indicating whether NA-values should be stripped before the computation proceeds.

See Also

rowSds, colSums

Examples

Run this code
set.seed(2016); dat1 <- matrix(c(runif(200) +rep(1:10,20)), ncol=10)
head(rowGrpMeans(dat1, gr=gl(4, 3, labels=LETTERS[1:4])[2:11]))

Run the code above in your browser using DataLab