Extract.sparse3Darray | R Documentation |
Extract or replace entries in a sparse three-dimensional array.
## S3 method for class 'sparse3Darray'
x[i, j, k, drop=TRUE, ...]
## S3 replacement method for class 'sparse3Darray'
x[i, j, k, ...] <- value
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. |
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
and k
are integer vectors,
the subset is the Cartesian product (i.e. all cells in the array
identified by an entry of i
, an entry of j
and
an entry of k
).
Some or all of the arguments i
, j
and k
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
and k
may be logical
vectors (with the value TRUE
assigned to entries that should
be included).
Arguments i
, j
and k
may be
character vectors with entries matching the corresponding
dimnames
.
Argument i
may be an integer matrix with 3 columns
(and the arguments j,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).
[.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.
.
sparse3Darray
,
methods.sparse3Darray
.
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, ]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.