colAvgsPerRowSet {DelayedMatrixStats}R Documentation

Applies a row-by-row (column-by-column) averaging function to equally-sized subsets of matrix columns (rows)

Description

Applies a row-by-row (column-by-column) averaging function to equally-sized subsets of matrix columns (rows). Each subset is averaged independently of the others.

Usage

colAvgsPerRowSet(X, W = NULL, cols = NULL, S, FUN = colMeans, ...,
  tFUN = FALSE)

rowAvgsPerColSet(X, W = NULL, rows = NULL, S, FUN = rowMeans, ...,
  tFUN = FALSE)

## S4 method for signature 'DelayedMatrix'
colAvgsPerRowSet(X, W = NULL, cols = NULL, S,
  FUN = colMeans, ..., force_block_processing = FALSE, tFUN = FALSE)

## S4 method for signature 'DelayedMatrix'
rowAvgsPerColSet(X, W = NULL, rows = NULL, S,
  FUN = rowMeans, ..., force_block_processing = FALSE, tFUN = FALSE)

Arguments

X

A NxM DelayedMatrix.

W

An optional numeric NxM matrix of weights.

cols

A vector indicating subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

S

An integer KxJ matrix specifying the J subsets. Each column holds K column (row) indices for the corresponding subset.

FUN

The row-by-row (column-by-column) function used to average over each subset of X. This function must accept a numeric NxK (KxM) matrix and the logical argument na.rm (which is automatically set), and return a numeric vector of length N (M).

...

Additional arguments passed to specific methods.

tFUN

If TRUE, the NxK (KxM) matrix passed to FUN() is transposed first.

rows

A vector indicating subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

force_block_processing

FALSE (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to TRUE (typically not advised). The block-processing strategy loads one or more (depending on getAutoBlockSize()) columns (colFoo()) or rows (rowFoo()) into memory as an ordinary base::array.

Details

If argument S is a single column vector with indices 1:N, then rowAvgsPerColSet(X, S = S, FUN = rowMeans) gives the same result as rowMeans(X). Analogously, for colAvgsPerRowSet().

Value

Returns a numeric JxN (MxJ) matrix, where row names equal rownames(X) (colnames(S)) and column names colnames(S) (colnames(X)).

Examples

# A DelayedMatrix with a 'DataFrame' seed
dm_DF <- DelayedArray(S4Vectors::DataFrame(C1 = rep(1L, 5),
                                           C2 = as.integer((0:4) ^ 2),
                                           C3 = seq(-5L, -1L, 1L)))
colAvgsPerRowSet(dm_DF, S = matrix(1:2, ncol = 2))

rowAvgsPerColSet(dm_DF, S = matrix(1:2, ncol = 1))

[Package DelayedMatrixStats version 1.4.0 Index]