sparse2dense: Converts sparse matrix to dense matrix.

Description Usage Arguments See Also Examples

Description

This function handles can distinguish between symmetric and non symmetric matrices when given sparse matrix can be interpreted as square.

Usage

1
2
3
4
5
6
sparse2dense(
  sparse.as.df,
  N = NULL,
  balancing = TRUE,
  missing.cells.na = FALSE
)

Arguments

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 function

balancing

logical, if perform balancing; see balancing description for information on function behaviour when N is NULL

missing.cells.na

logical, if TRUE then substitute cells with i,j coordinates missing in given sparse matrix with NA, otherwise substitute with 0

See Also

balancing for balancing

Examples

 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)

rz6/DIADEM documentation built on Dec. 31, 2019, 3:51 a.m.