View source: R/utilities_Matrix.R
Matrix | R Documentation |
matsbyname
packageThe matsbyname
package uses Matrix
objects for its
default data representation, taking advantage
of the sparse matrix capabilities of Matrix
compared
to the base matrix
class.
This function routes to Matrix::Matrix()
, with some important
differences. See details.
Matrix(
data = NA,
nrow = 1,
ncol = 1,
byrow = FALSE,
dimnames = base::dimnames(data),
sparse = NULL,
doDiag = FALSE,
forceCheck = FALSE,
rowtype = matsbyname::rowtype(data),
coltype = matsbyname::coltype(data)
)
data |
An optional numeric data vector or |
nrow |
When |
ncol |
When |
byrow |
A boolean. If |
dimnames |
A dimnames attribute for the Matrix: a list of two character components.
Default is |
sparse |
A boolean or |
doDiag |
A boolean indicating if a |
forceCheck |
A boolean indicating if the checks for structure should happen
when |
rowtype |
The rowtype for the result. Default is |
coltype |
The coltype for the result. Default is |
This function NEVER creates a symmetric matrix
(e.g., dsCMatrix
, dsyMatrix
, dsRMatrix
, lsyMatrix
, nsyMatrix
),
because symmetric matrices do not respect some future changes to dimnames
,
which can cause information loss in the matsbyname
context.
A non-symmetric Matrix
is assured by calling as(out, "generalMatrix")
on the outgoing Matrix
object.
This function enables setting row and column types at the time of construction
with the rowtype
and coltype
arguments.
This function has different defaults compared to Matrix::Matrix()
, including
Here, the default for doDiag
is FALSE
,
while the default for doDiag
is TRUE
for Matrix::Matrix()
.
Preserves rowtype and coltype on data
.
This function is vectorized over a list of matrix
objects supplied to data
.
See examples.
A Matrix
object.
# matsbyname::Matrix() will not create a Matrix with a symmetric subclass.
# dgCMatrix is a general matrix.
matsbyname::Matrix(c(1, 0, 2,
0, 0, 0,
2, 0, 0), byrow = TRUE, nrow = 3, ncol = 3)
# But Matrix::Matrix() will create a symmetric matrix.
# dsCMatrix is a symmetric matrix.
Matrix::Matrix(c(1, 0, 2,
0, 0, 0,
2, 0, 0), byrow = TRUE, nrow = 3, ncol = 3)
# matsbyname::Matrix() will not create a diagonal matrix.
# dgeMatrix is a general matrix.
matsbyname::Matrix(c(1, 0,
0, 1), byrow = TRUE, nrow = 2, ncol = 2)
# But Matrix::Matrix() will create a diagonal matrix.
# ddiMatrix is a diagonal matrix.
Matrix::Matrix(c(1, 0,
0, 1), byrow = TRUE, nrow = 2, ncol = 2)
# This function is vectorized over lists of `matrix` objects in `data`.
m <- matrix(c(1, 0, 2,
0, 0, 0,
2, 0, 0), byrow = TRUE, nrow = 3, ncol = 3)
matsbyname::Matrix(list(m, m))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.