View source: R/sparse3Darray.R
| as.sparse3Darray | R Documentation |
Convert other kinds of data to a sparse three-dimensional array.
as.sparse3Darray(x, ...)
x |
Data in another format (see Details). |
... |
Ignored. |
This function converts data in various formats
into a sparse three-dimensional array (object of class
"sparse3Darray").
The argument x can be
a sparse three-dimensional array (class "sparse3Darray")
an array
a matrix,
which will be interpreted as an array
with dimension c(dim(x), 1)
a sparse matrix (inheriting class "sparseMatrix" in the
Matrix package)
which will be interpreted as an array
with dimension c(dim(x), 1)
a vector of atomic values,
which will be interpreted as an array of dimension
c(length(x), 1, 1)
a sparse vector (inheriting class "sparseVector" in the
Matrix package)
which will be interpreted as an array of dimension c(x@length, 1, 1)
a list of matrices with the same dimensions,
which will be interpreted as slices A[,,k] of an array A
a list of sparse matrices (each inheriting class
"sparseMatrix" in the Matrix package) with the same
dimensions,
which will be interpreted as slices A[,,k] of an array A.
Sparse three-dimensional array (object of class "sparse3Darray").
.
sparse3Darray
A <- array(c(1,3,0,0,0,0,0,4,0,2,0,5,
0,0,1,0,0,0,1,0,0,0,1,0),
dim=c(3,4,2))
#' array to sparse array
B <- as.sparse3Darray(A) # positive extent
#' list of matrices to sparse array
B <- as.sparse3Darray(list(A[,,1], A[,,2]))
#' matrix to sparse array
B1 <- as.sparse3Darray(A[,,1])
#' vector to sparse array
B11 <- as.sparse3Darray(A[,1,1])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.