sparseMatrix-utils: sparseMatrix utilities

Description Usage Arguments Value See Also Examples

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## 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

1
2
3
4
5
6
7
8
9
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 documentation built on March 25, 2021, 6:01 p.m.