Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sparseMatrix-utils

sparseMatrix utilities


Description

Some utilities to operate natively on sparseMatrix objects (e.g. dgCMatrix and lgCMatrix objects) from the Matrix package. Mostly for internal use by the DelayedArray package.

Usage

## rowsum() and colsum() S4 generics:

#rowsum(x, group, reorder=TRUE, ...)
#colsum(x, group, reorder=TRUE, ...)

## Default methods:

## S4 method for signature 'ANY'
rowsum(x, group, reorder=TRUE, ...)
## S4 method for signature 'ANY'
colsum(x, group, reorder=TRUE, ...)

## rowsum() method for dgCMatrix objects:

## S4 method for signature 'dgCMatrix'
rowsum(x, group, reorder=TRUE, ...)

Arguments

x

A numeric matrix-like object.

group, reorder, ...

See ?base::rowsum for a description of these arguments.

Value

See ?base::rowsum for the value returned by the default rowsum method.

The default colsum method returns t(rowsum(t(x), group, reorder=reorder, ...)).

See Also

Examples

m0 <- rsparsematrix(1e5, 800, density=0.15)  # sparse representation
m <- as.matrix(m0)                           # dense representation
group <- sample(20, nrow(m), replace=TRUE)

## 'rowsum(m0)' is about 4x faster than 'rowsum(m)':
rs0 <- rowsum(m0, group)
rs <- rowsum(m, group)

stopifnot(identical(rs0, rs))

DelayedArray

A unified framework for working transparently with on-disk and in-memory array-like datasets

v0.16.3
Artistic-2.0
Authors
Hervé Pagès <hpages.on.github@gmail.com>, with contributions from Peter Hickey <peter.hickey@gmail.com> and Aaron Lun <infinite.monkeys.with.keyboards@gmail.com>
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.