binMatrix: Column-wise binning of a numeric matrix

Description Usage Arguments Details Author(s) Examples

View source: R/src_binMatrix.R

Description

Perform binning on a numeric matrix. Divide the matrix in ncol(mat)/byNcols columns and then on each of these apply rowMeans, combine into a binned output matrix.

Usage

1
binMatrix(mat, byNcols, method = "mean", drop.uneven = FALSE)

Arguments

mat

numeric matrix

byNcols

average this number of consecutive columns

method

aggregation method, "mean" or "median"

drop.uneven

logical, whether to drop columns if ncol(mat)/byNcols is odd, see details.

Details

'drop.uneven' determines what to do with columns if ncol(mat)/byNcols is odd. Say you have 99 columns and want to bin into 10er columns, means the last 9 would be orphans. With FALSE these would simply be averaged and returned with the rest, or TRUE would be discarded. If mat has fewer columns that one sets byNcols then with FALSE the function returns all columns averaged, or with TRUE a stop is returned.

Author(s)

Alexander Toenges

Examples

1
2
mat <- sapply(paste0("Sample",seq(1,99)), function(x) rnorm(100,20,3))
binned <- binMatrix(mat = mat, byNcols = 3, method = "mean")

ATpoint/diffanalyseR documentation built on Oct. 8, 2021, 10:11 p.m.