colAvgsPerRowSet-xgCMatrix-method: Calculates for each row (column) a summary statistic for...

Description Usage Arguments Details Value See Also Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## S4 method for signature 'xgCMatrix'
colAvgsPerRowSet(
  X,
  W = NULL,
  cols = NULL,
  S,
  FUN = colMeans2,
  ...,
  na.rm = NA,
  tFUN = FALSE
)

## S4 method for signature 'xgCMatrix'
rowAvgsPerColSet(
  X,
  W = NULL,
  rows = NULL,
  S,
  FUN = rowMeans2,
  ...,
  na.rm = NA,
  tFUN = FALSE
)

Arguments

X

An NxM matrix-like object.

W

An optional numeric NxM matrix of weights.

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.

na.rm

(logical) Argument passed to FUN() as na.rm = na.rm. If NA (default), then na.rm = TRUE is used if X or S holds missing values, otherwise na.rm = FALSE.

tFUN

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

rows

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

Details

**Note**: the handling of missing parameters differs from [matrixStats::colAvgsPerRowSet()]. The 'matrixStats' version always removes ‘NA'’s if there are any in the data. This method however does whatever is passed in the '...' parameter.

Value

Returns a numeric JxN (MxJ) matrix.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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)

sparseMatrixStats documentation built on Feb. 4, 2021, 2 a.m.