rowAvgsPerColSet {MatrixGenerics}R Documentation

Calculates for each row (column) a summary statistic for equally sized subsets of columns (rows)

Description

Calculates for each row (column) a summary statistic for equally sized subsets of columns (rows).

Usage

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

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

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

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

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

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

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

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

Arguments

X

An NxM matrix-like object.

W

An optional numeric NxM matrix of weights.

rows, cols

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

S

An integer KxJ matrix that specifying the J subsets. Each column hold K column (row) indices for the corresponding subset. The range of values is [1, M] ([1,N]).

FUN

A row-by-row (column-by-column) summary statistic function. It is applied to to each column (row) subset of X that is specified by S.

...

Additional arguments passed to FUN.

tFUN

If TRUE, X is transposed before it is passed to FUN.

Details

The S4 methods for x of type matrix, array, or numeric call matrixStats::rowAvgsPerColSet / matrixStats::colAvgsPerRowSet.

Value

Returns a numeric JxN (MxJ) matrix.

See Also

Examples

  mat <- matrix(rnorm(20), nrow = 5, ncol = 4)
  mat[2, 1] <- NA
  mat[3, 3] <- Inf
  mat[4, 1] <- 0
  
  print(mat)
  
  S <- matrix(1:ncol(mat), ncol = 2)
  print(S)
  
  rowAvgsPerColSet(mat, S = S, FUN = rowMeans)
  rowAvgsPerColSet(mat, S = S, FUN = rowVars)


[Package MatrixGenerics version 1.0.2 Index]