Maps edgelist to adjacency matrix

el2adj(
  edge.list,
  select_cols = NULL,
  multiedge = FALSE,
  aggr_expression = NULL,
  nodes = NULL,
  sparse = TRUE,
  drop_names = FALSE,
  directed = NULL,
  selfloops = NULL
)

Arguments

edge.list

dataframe containing a (weighted) edgelist.

select_cols

optional vector of 3 (2 for multi-graphs) elements specifying which columns are the source,target, and attributes from which building the graph. Otherwise Column 1 is assumed to be the source, column 2 the target, column 3 the attribute. In the case of multi-graphs, the third element is not needed and the number of edges between each pair of vertices is computed according to 'aggr_expression'.

multiedge

boolean, are there multiple edges? defaults to FALSE.

aggr_expression

string, the expression used to compute the aggregated value in the adjacency matrix in the presence of multiedges. It defaults to 'dplyr::n()'. If `edge.list` contains other columns such as `weight`, examples of `aggr_expression` could be `"mean(weight)"` to report the average of the `weight` column of the multiedges, `"min(weight)"` to report the minimum of the `weight` column of the multiedges.

nodes

optional vector containing all node names in case disconnected nodes should be included.

sparse

boolean, return sparse matrix? default to TRUE

drop_names

boolean, drop names from matrix and return a vector of names together with the matrix. This option saves considerable memory when dealing with graphs with long node names.

directed

boolean, optional parameter, if FALSE, forces to undirected upper triangular adjacency matrix

selfloops

boolean, optional parameter, if ignores selfloops.

Value

the (weighted) adjacency matrix corresponding the edgelist passed. If `drop_names` is TRUE, returns a list with the adjacency matrix and a vector with node names.

Examples

el <- data.frame(from= c('a','b','b','c','d','d'), to = c('b','c','d','a','b','a'), attr= c( 12, 6, 12 , 6 , 6 , 6 )) adj <- el2adj(el)