rowratio: Calculate column raito of a matrix or data frame based on a...

View source: R/rowratio.R

rowratioR Documentation

Calculate column raito of a matrix or data frame based on a grouping variable

Description

Compute column ratio across rows of a numeric matrix-like object for each level of a grouping variable.

Usage

rowratio(x, group, reorder = T, na.rm = T)

Arguments

x

a matrix or data frame.

group

a vector of factor giving grouping, with one element per row of x.

reorder

if TRUE, then the result will be in order of row names of x. If row names of x is null, the results is not reordered.

na.rm

logical (TRUE or FALSE). Should NA (including NaN) values be replaced by value 0?

Value

rowratio returns a matrix or data frame containing the ratios. There will be one row per unique value of group.

See Also

rowsum, rowmean

Examples

x <- matrix(runif(50), ncol = 5)
group <- sample(1:4, 10, TRUE)
xratio <- rowratio(x, group)


wyguo/TSIS documentation built on May 21, 2023, 12:36 a.m.