marginSumsSparse {spatstat.sparse} | R Documentation |
Margin Sums of a Sparse Matrix or Sparse Array
Description
For a sparse matrix or sparse array, compute the sum of array entries for a specified margin or margins.
Usage
marginSumsSparse(X, MARGIN)
Arguments
X |
A matrix, an array,
a sparse matrix (of class |
MARGIN |
Integer or integer vector specifying the margin or margins. |
Details
This function computes the equivalent of
apply(X, MARGIN, sum)
for sparse matrices and arrays X
. The argument X
may be
a matrix
an array of any number of dimensions
a sparse matrix (object inheriting class
"sparseMatrix"
in the Matrix package)a sparse three-dimensional array (of class
"sparse3Darray"
from the spatstat.sparse package).
In the first two cases, the computation is performed by
calling apply(X, MARGIN, sum)
and the result is a vector, matrix or array.
In the last two cases, the result is a single value, a sparse vector,
a sparse matrix, or a sparse three-dimensional array.
Value
A single value, vector, matrix, array,
sparse vector (class "sparseVector"
in the Matrix
package), sparse matrix (class "sparseMatrix"
in the
Matrix package), or sparse three-dimensional array
(class "sparse3Darray"
from the spatstat.sparse package).
Author(s)
Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner rolfturner@posteo.net and Ege Rubak rubak@math.aau.dk.
See Also
Examples
M <- sparse3Darray(i=1:3, j=c(3,1,2), k=4:2,
x=round(runif(3), 2), dims=rep(4, 3))
marginSumsSparse(M, 1:2)
marginSumsSparse(M, 1)
marginSumsSparse(M, integer(0)) # equivalent to sum(M)