Learn R Programming

netdiffuseR (version 1.20.2)

as_dgCMatrix: Coerce a matrix-like objects to dgCMatrix (sparse matrix)

Description

This helper function allows easy coercion to sparse matrix objects from the Matrix package, dgCMatrix.

Usage

as_dgCMatrix(x, make.dimnames = TRUE, ...)

as.dgCMatrix(x, make.dimnames = TRUE, ...)

as_spmat(x, make.dimnames = TRUE, ...)

# S3 method for default as_dgCMatrix(x, make.dimnames = TRUE, ...)

# S3 method for diffnet as_dgCMatrix(x, make.dimnames = TRUE, ...)

# S3 method for array as_dgCMatrix(x, make.dimnames = TRUE, ...)

# S3 method for igraph as_dgCMatrix(x, make.dimnames = TRUE, ...)

# S3 method for network as_dgCMatrix(x, make.dimnames = TRUE, ...)

# S3 method for list as_dgCMatrix(x, make.dimnames = TRUE, ...)

Arguments

x

An object to be coerced into a sparse matrix.

make.dimnames

Logical scalar. When TRUE, it makes sure that the returned object has dimnames.

...

Further arguments passed to the method.

Value

Either a list with dgCMatrix objects or a dgCMatrix object.

Details

In the case of the igraph and network methods, ... is passed to as_adj and as.matrix.network respectively.

Examples

Run this code
# NOT RUN {
set.seed(1231)
x <- rgraph_er(10)

# From matrix object
as_dgCMatrix(as.matrix(x))

# From a network object
as_dgCMatrix(network::as.network(as.matrix(x)))

# From igraph object
as_dgCMatrix(igraph::graph_from_adjacency_matrix(x))

# From array
myarray <- array(dim=c(10,10,2))
myarray[,,1] <- as.matrix(x)
myarray[,,2] <- as.matrix(x)

myarray
as_dgCMatrix(myarray)

# From a diffnet object
ans <- as_dgCMatrix(medInnovationsDiffNet)
str(ans)


# }

Run the code above in your browser using DataLab