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