colSds: Standard deviation of columns and rows of large matrices

View source: R/utils.R

colSdsR Documentation

Standard deviation of columns and rows of large matrices

Description

Produce the same result as apply(x, 2, sd) and apply(x, 1, sd), respectively. without coercing matrix to dense matrix. Values are not identical to sd() because of the floating point precision issue in C++.

Usage

colSds(x, use_nan = FALSE)

rowSds(x, use_nan = FALSE)

Arguments

x

a base::matrix or Matrix::Matrix object.

use_nan

if TRUE, return NaN for columns or rows with all zero. Only used when x is a sparse matrix.

Value

a numeric vector

Examples

mt <- Matrix::rsparsematrix(100, 100, 0.9)
colSds(mt)
apply(mt, 2, sd) # the same

proxyC documentation built on Oct. 30, 2026, 9:08 a.m.