dsm.canonical.matrix | R Documentation |
Test whether a co-occurrence matrix is represented in a DSM canonical format, or convert matrix to canonical format.
dsm.is.canonical(x, nonneg.check = FALSE) dsm.canonical.matrix(x, triplet = FALSE, annotate = FALSE, nonneg.check = FALSE)
x |
a dense or sparse DSM co-occurrence matrix |
nonneg.check |
if |
triplet |
if |
annotate |
if |
Note that conversion into canonical format may result in unnecessary copying of x
, especially if annotate=TRUE
.
For optimal performance, set annotate=FALSE
whenever possible and do not call dsm.canonical.matrix()
as a no-op.
Instead of
M <- dsm.canonical.matrix(M, annotate=TRUE, nonneg=TRUE)
use
M.flags <- dsm.is.canonical(M, nonneg=FALSE) if (!M.flags$canonical) M <- dsm.canonical.matrix(M) M.flags <- dsm.is.canonical(M, nonneg=TRUE)
If nonneg.check=FALSE
and x
has an attribute nonneg
, its value is accepted without validation.
Checking non-negativity can be expensive and create substantial memory overhead. It is guaranteed to be efficient for a matrix in canonical format.
dsm.is.canonical()
returns a data frame containing a single row with the following items:
sparse |
whether |
canonical |
whether |
nonneg |
whether all cells of |
dsm.canonical.matrix()
returns a matrix in canonical DSM format, i.e.
of class matrix
for a dense matrix (even if x
is a denseMatrix
object);
of class dgCMatrix
for a sparse matrix.
If triplet=TRUE
and x
is sparse, it returns a matrix of class dgTMatrix
, which is not a canonical format.
If annotate=TRUE
, the returned matrix has attributes sparse
and nonneg
(possibly NA
).
Stephanie Evert (https://purl.org/stephanie.evert)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.