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

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 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, ]

[Package spatstat.sparse version 3.0-3 Index]