is_sparse | R Documentation |
is_sparse
indicates whether an object (typically array-like)
uses a sparse representation of the data or not.
Note that this is about data representation and not about the
data itself. For example, is_sparse()
always returns FALSE
on an ordinary matrix, even if the matrix contains 99% zeros,
because the data in such a matrix is always stored in a dense form.
OTOH is_sparse()
always returns TRUE
on a
SparseArray derivative from the SparseArray
package, or on a dgCMatrix object from the Matrix
package, even if the data contains no zeros, because these objects
use a sparse representation of the data.
is_sparse(x)
x |
Any object, but will typically be an array-like object. Examples of array-like objects: ordinary arrays,
SparseArray objects from the SparseArray package,
dgCMatrix objects from the Matrix package,
DelayedArray objects from the DelayedArray
package, or any object with an array semantic (i.e. an object for
which |
TRUE
or FALSE
read_block
to read a block of data from an
array-like object.
array and matrix objects in base R.
dgCMatrix objects implemented in the Matrix package.
m <- matrix(0L, nrow=50, ncol=20)
stopifnot(identical(is_sparse(m), FALSE))
dgc <- as(m + runif(1000), "dgCMatrix")
stopifnot(identical(is_sparse(dgc), TRUE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.