Convert adjacency list to an adjacency matrix

adjacencyList2Matrix(lt, square = FALSE)

Arguments

lt

A data frame which contains adjacency list.

square

Should the returned matrix be a square matrix?

Examples

set.seed(123) df = data.frame(from = sample(letters, 10, replace = TRUE), to = sample(letters, 10, replace = TRUE), value = 1:10) adjacencyList2Matrix(df)
#> n v y z e s i c #> o 1 0 0 0 0 0 0 0 #> s 0 2 0 0 0 0 0 0 #> n 0 0 3 0 0 0 0 0 #> c 0 0 0 4 0 0 0 0 #> j 0 0 0 0 5 0 0 0 #> r 0 0 0 0 0 6 0 0 #> v 0 0 7 0 0 0 0 0 #> k 0 0 8 0 0 0 0 0 #> e 0 0 0 0 0 0 9 0 #> t 0 0 0 0 0 0 0 10
adjacencyList2Matrix(df, square = TRUE)
#> o s n c j r v k e t y z i #> o 0 0 1 0 0 0 0 0 0 0 0 0 0 #> s 0 0 0 0 0 0 2 0 0 0 0 0 0 #> n 0 0 0 0 0 0 0 0 0 0 3 0 0 #> c 0 0 0 0 0 0 0 0 0 0 0 4 0 #> j 0 0 0 0 0 0 0 0 5 0 0 0 0 #> r 0 6 0 0 0 0 0 0 0 0 0 0 0 #> v 0 0 0 0 0 0 0 0 0 0 7 0 0 #> k 0 0 0 0 0 0 0 0 0 0 8 0 0 #> e 0 0 0 0 0 0 0 0 0 0 0 0 9 #> t 0 0 0 10 0 0 0 0 0 0 0 0 0 #> y 0 0 0 0 0 0 0 0 0 0 0 0 0 #> z 0 0 0 0 0 0 0 0 0 0 0 0 0 #> i 0 0 0 0 0 0 0 0 0 0 0 0 0