Skip to contents

Efficiently computes the variance of each row for either a base R dense matrix or a sparse dgCMatrix, via a single Rcpp entry point. Logs progress messages to the R console.

Usage

get_rowVar(M, verbose = FALSE)

Arguments

M

A numeric matrix (base R matrix) or a sparse matrix of class "dgCMatrix".

verbose

Logical. If TRUE (default), prints progress and informational messages.

Value

A numeric vector of length nrow(M) containing the variance of each row.

Details

Dispatches in C++ between dense and sparse implementations to avoid unnecessary overhead or external dependencies. Uses compressed-column traversal for sparse inputs.

Note

Only 32-bit integer indices are supported, due to limitations in R's internal matrix representations. This function will not work with matrices that exceed the 32-bit integer indexing range.

Examples

if (FALSE) { # \dontrun{
  library(Matrix)
  # Dense example
  dm <- matrix(rnorm(1000), nrow = 100)
  get_rowVar(dm)
  # Sparse example
  sm <- rsparsematrix(100, 10, density = 0.1)
  get_rowVar(sm)
} # }