sparse3Darray {spatstat.sparse} | R Documentation |
Create a Sparse Three-Dimensional Array
Description
Create a sparse representation of a three-dimensional array.
Usage
sparse3Darray(i = integer(0), j = integer(0), k = integer(0),
x = numeric(0),
dims = c(max(i), max(j), max(k)), dimnames = NULL,
strict = FALSE, nonzero = FALSE)
Arguments
i , j , k |
Integer vectors of equal length (or length 1), specifying the cells in the array which have non-zero entries. |
x |
Vector (numeric, integer, logical or complex)
of the same length as |
dims |
Dimension of the array. An integer vector of length 3. |
dimnames |
Names for the three margins of the array. Either |
strict |
Logical value specifying whether to enforce the rule that
each entry in |
nonzero |
Logical value specifying whether to remove any entries
of |
Details
An array A
is three-dimensional if it is indexed by
three integer indices, so that A[i,j,k]
specifies an element of
the array. The array is called sparse if only a small fraction of the
entries are non-zero. A sparse array can be represented economically
by listing only the entries which are non-zero.
The spatstat.sparse package defines the class
sparse3Darray
of sparse three-dimensional arrays.
These arrays can have numeric, integer, logical, or complex
entries.
The function sparse3Darray
creates an object of class
"sparse3Darray"
. This object is essentially a list containing
the vectors i,j,k,x
and the arguments dims,dimnames
.
The arguments i,j,k,x
should be vectors of equal length
identifying the cells in the array which have non-zero entries (indexed
by i,j,k
) and giving the values in these cells (given by x
).
The default behaviour of sparse3Darray
is to accept the arguments i,j,k,x
without modifying them.
This would allow some entries of x
to be equal to zero,
and would allow a cell in the array to be referenced more than once
in the indices i,j,k
.
If nonzero=TRUE
, entries will be removed if the x
value
equals zero.
If strict=TRUE
, entries which refer to the same cell in the
array will be combined into a single entry by summing the x
values.
Value
An object of class "sparse3Darray"
.
Author(s)
Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner rolfturner@posteo.net and Ege Rubak rubak@math.aau.dk.
See Also
Examples
## creation by specifying nonzero elements
M <- sparse3Darray(i=1:3, j=c(3,1,2), k=4:2,
x=runif(3), dims=rep(4, 3))
M
## duplicate entries
Mn <- sparse3Darray(i=c(1,1,2), j=c(2,2,1), k=c(3,3,2),
x=runif(3), dims=rep(3, 3))
## cumulate entries in duplicate positions
Ms <- sparse3Darray(i=c(1,1,2), j=c(2,2,1), k=c(3,3,2),
x=runif(3), dims=rep(3, 3), strict=TRUE)