#' turn list in to simnetr_matrix
#'
#' @param x An adjacency list
#' @return adjacency matrix of class simnetr_matrix
#' @export
list2matrix <- function(x) {
stopifnot(is.list(x))
N <- length(x)
network <- matrix(0L, nrow = N, ncol = N)
for (i in 1:N) {
network[i, x[[i]]] <- 1L
}
return(network)
}
#' turn matrix in to simnetr_list
#' @param x An adjacency matrix
#' @return adjacency list of class simnetr_list
#' @export
matrix2list <- function(x) {
stopifnot(is.matrix(x))
N <- nrow(x)
network <- vector("list", N)
for (i in 1:N) {
network[[i]] <- which(x[i,] == 1)
}
return(network)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.