sparseMatrix-utils {DelayedArray} | R Documentation

## 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

- DelayedMatrix-utils in this package for the `rowsum` and `colsum` methods defined for DelayedMatrix objects.

- `base::rowsum` in the base package for the default `rowsum` method.

- dgCMatrix objects in the Matrix package.

### 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))

[Package DelayedArray version 0.18.0 Index]