marginSumsSparse | R Documentation |
For a sparse matrix or sparse array, compute the sum of array entries for a specified margin or margins.
marginSumsSparse(X, MARGIN)
X |
A matrix, an array,
a sparse matrix (of class |
MARGIN |
Integer or integer vector specifying the margin or margins. |
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.
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).
.
apply
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.