R/from.adjacency.R

#' Adjacency Matrix to \code{fastnet}
#'
#' @description Transform an adjacency matrix to an ego-centric list form used in \code{fastnet}.
#' @param adj.mat	The input adjacency matrix
#' @return A list containing the nodes of the network and their respective neighbors.
#' @author Xu Dong, Christian Llano.
#' @examples
#' adj.mat <- matrix(c(0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0), nrow = 4, ncol = 4)
#' g <- from.adjacency(adj.mat)
#'
#' @export

from.adjacency <- function (adj.mat){

  if (!is.matrix(adj.mat)) stop("Parameter 'adj.mat' must be a matrix", call. = FALSE)
  net <- lapply( igraph::as_adj_list( igraph::graph_from_adjacency_matrix(adj.mat), mode = "out" ),
                 as.numeric ) ## use as.numeric to remove the "igraph.vs" class
  net
}

Try the fastnet package in your browser

Any scripts or data that you put into this service are public.

fastnet documentation built on Jan. 13, 2021, 5:28 p.m.