Description Usage Arguments See Also Examples
This function handles can distinguish between symmetric and non symmetric matrices when given sparse matrix can be interpreted as square.
1 2 3 4 5 6 | sparse2dense(
sparse.as.df,
N = NULL,
balancing = TRUE,
missing.cells.na = FALSE
)
|
sparse.as.df |
data.frame with sparse matrix containing 3 columns: i, j, val |
N |
positive integer, optional desired dimension of dense matrix enforced with |
balancing |
logical, if perform balancing; see |
missing.cells.na |
logical, if TRUE then substitute cells with i,j coordinates missing in given sparse matrix with NA, otherwise substitute with 0 |
balancing
for balancing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # produce dense matrix
mtx.dense <- matrix(1:24, ncol = 3)
# add some zeros
mtx.dense <- rbind(matrix.dense, c(0,100,0))
# construct sparse matrix
mtx.sparse <- dense2sparse(mtx.dense, add.diagonal = FALSE)
# get back dense matrix
sparse2dense(mtx.sparse, balancing = FALSE)
sparse2dense(mtx.sparse, balancing = FALSE, missing.cells.na = TRUE)
# symmetric matrices
mtx.sym <- matrix(1:16, ncol = 4)
mtx.sym <- mtx.sym + t(mtx.sym)
sparse2dense(dense2sparse(mtx.sym, add.diagonal = FALSE))
# square non symmetric matrices
mtx.sq <- matrix(1:16, ncol = 4)
mtx.sq[c(2,3,4,7,12)] <- 0
sparse2dense(mtx.sparse)
sparse2dense(mtx.sparse, missing.cells.na = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.