File: sparseMatrix-utils.Rd

package info (click to toggle)
r-bioc-delayedarray 0.24.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,480 kB
  • sloc: ansic: 727; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,874 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
\name{sparseMatrix-utils}

\alias{sparseMatrix-utils}

\alias{rowsum,ANY-method}
\alias{colsum,ANY-method}
\alias{rowsum.dgCMatrix}
\alias{rowsum,dgCMatrix-method}

\title{sparseMatrix utilities}

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

\usage{
## rowsum() and colsum() S4 generics:

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

## Default methods:

\S4method{rowsum}{ANY}(x, group, reorder=TRUE, ...)
\S4method{colsum}{ANY}(x, group, reorder=TRUE, ...)

## rowsum() method for dgCMatrix objects:

\S4method{rowsum}{dgCMatrix}(x, group, reorder=TRUE, ...)
}

\arguments{
  \item{x}{
    A numeric matrix-like object.
  }
  \item{group, reorder, ...}{
    See \code{?base::\link[base]{rowsum}} for a description of
    these arguments.
  }
}

\value{
  See \code{?base::\link[base]{rowsum}} for the value returned
  by the default \code{rowsum} method.

  The default \code{colsum} method returns
  \code{t(rowsum(t(x), group, reorder=reorder, ...))}.
}

\seealso{
  \itemize{
    \item \link{DelayedMatrix-utils} in this package for the \code{rowsum}
          and \code{colsum} methods defined for \link{DelayedMatrix} objects.

    \item \code{base::\link[base]{rowsum}} in the \pkg{base} package for
          the default \code{rowsum} method.

    \item \linkS4class{dgCMatrix} objects in the \pkg{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))
}
\keyword{methods}