Learn R Programming

spatstat.sparse (version 3.1-0)

marginSumsSparse: 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)

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

Arguments

X

A matrix, an array, a sparse matrix (of class "sparseMatrix" from the Matrix package) or a sparse three-dimensional array (of class "sparse3Darray" from the spatstat.sparse package).

MARGIN

Integer or integer vector specifying the margin or margins.

Author

Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner rolfturner@posteo.net and Ege Rubak rubak@math.aau.dk.

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.

See Also

Examples

Run this code
  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)

Run the code above in your browser using DataLab