colVars-xgCMatrix-method: Calculates the variance for each row (column) of a...

Description Usage Arguments Details Value See Also Examples

Description

Calculates the variance for each row (column) of a matrix-like object.

Usage

1
2
3
4
5
## S4 method for signature 'xgCMatrix'
colVars(x, rows = NULL, cols = NULL, na.rm = FALSE)

## S4 method for signature 'xgCMatrix'
rowVars(x, rows = NULL, cols = NULL, na.rm = FALSE)

Arguments

x

An NxK matrix-like object.

rows

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

cols

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

na.rm

If TRUE, NAs are excluded first, otherwise not.

Details

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

Value

Returns a numeric vector of length N (K).

See Also

Examples

1
2
3
4
5
6
7
8
9
mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
  mat[2, 1] <- NA
  mat[3, 3] <- Inf
  mat[4, 1] <- 0
  
  print(mat)
  
  rowVars(mat)
  colVars(mat)

Example output

Loading required package: MatrixGenerics
Loading required package: matrixStats

Attaching package:MatrixGenericsThe following objects are masked frompackage:matrixStats:

    colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
    colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
    colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
    colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
    colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
    colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
    colWeightedMeans, colWeightedMedians, colWeightedSds,
    colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
    rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
    rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
    rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
    rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
    rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
    rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
    rowWeightedSds, rowWeightedVars

             [,1]       [,2]       [,3]
[1,] -0.002654082 -1.4403892  1.3706918
[2,]           NA  1.0348631  0.3255234
[3,]  1.336176343  1.4209654        Inf
[4,]  0.000000000 -1.8971467 -0.4056419
[5,]  1.222255357  0.8513312 -0.3000324
[1] 1.9758896        NA       NaN 0.9980496 0.6300972
[1]       NA 2.372138      NaN

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