Extract.sparse3Darray {spatstat.sparse} | R Documentation |
Extract or Replace Entries in a Sparse Array
Description
Extract or replace entries in a sparse three-dimensional array.
Usage
## S3 method for class 'sparse3Darray'
x[i, j, k, drop=TRUE, ...]
## S3 replacement method for class 'sparse3Darray'
x[i, j, k, ...] <- value
Arguments
x |
Sparse three-dimensional array
(object of class |
i , j , k |
Subset indices for each dimension of the array. See Details. |
value |
Replacement value for the subset. |
drop |
Logical value indicating whether to return a lower-dimensional object (matrix or vector) when appropriate. |
... |
Ignored. This argument is required for compatibility with the generic function. |
Details
These functions are defined for a sparse three-dimensional array x
.
They extract a designated subset of the array,
or replace the values in the designated subset.
The function [.sparse3Darray
is a method for the generic
subset extraction operator [
.
The function [<-.sparse3Darray
is a method for the generic
subset replacement operator [<-
.
These methods use the same indexing rules as the subset operator for full arrays:
If
i
,j
andk
are integer vectors, the subset is the Cartesian product (i.e. all cells in the array identified by an entry ofi
, an entry ofj
and an entry ofk
).Some or all of the arguments
i
,j
andk
may be missing from the call; a missing index argument is interpreted as meaning that all possible values of that index are allowed.Arguments
i
,j
andk
may be logical vectors (with the valueTRUE
assigned to entries that should be included).Arguments
i
,j
andk
may be character vectors with entries matching the correspondingdimnames
.Argument
i
may be an integer matrix with 3 columns (and the argumentsj,k
should be absent). Each row of the matrix contains the indices of one cell in the array.
If the designated subset lies within the array bounds, then
the result of [
will be a sparse three-dimensional array,
sparse matrix or sparse vector. If drop=FALSE
the result
will always be three-dimensional; if drop=TRUE
(the default)
the result will be reduced to two or one dimensions when appropriate.
If the designated subset does not lie within the array bounds, then
the result of [
will be a full three-dimensional array,
matrix or vector containing NA
values at the positions that
were outside the array bounds.
The result of [<-
is always a sparse three-dimensional array.
If the designated subset did not lie within the array bounds of
x
, then the array bounds will be extended (with a warning message).
Value
[.sparse3Darray
returns either
a sparse three-dimensional array (class "sparse3Darray"
),
a sparse matrix (class sparseMatrix
in the Matrix package),
a sparse vector (class sparseVector
in the Matrix package),
or in some cases a full array, matrix or vector.
[<-.sparse3Darray
returns another sparse three-dimensional
array.
Author(s)
Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner rolfturner@posteo.net and Ege Rubak rubak@math.aau.dk.
See Also
sparse3Darray
,
methods.sparse3Darray
.
Examples
M <- sparse3Darray(i=1:4, j=sample(1:4, replace=TRUE),
k=c(1,2,1,2), x=1:4, dims=c(5,5,2))
dimnames(M) <- list(letters[1:5], LETTERS[1:5], c("yes", "no"))
M[ 3:4, , ]
M[ 3:4, 2:4, ]
M[ 4:3, 4:2, 1:2]
M[, 3, ]