Network Analysis in the Tidyverse
Massimo Franceschet
Prof. of Data Science, University of Udine (Italy)

as_adjacency_matrix(g)
1 2 3 4 5 6
1 0 1 0 0 1 0
2 1 0 1 1 0 0
3 0 1 0 1 1 1
4 0 1 1 0 0 0
5 1 0 1 0 0 0
6 0 0 1 0 0 0

as_adjacency_matrix(g,
attr="weight")
1 2 3 4 5 6
1 0 1 0 0 2 0
2 1 0 2 3 0 0
3 0 2 0 4 5 1
4 0 3 4 0 0 0
5 2 0 5 0 0 0
6 0 0 1 0 0 0
# get the adjacency matrix of network g A = as_adjacency_matrix(g)# get the weighted adjacency matrix of weighted network g A = as_adjacency_matrix(g, attr = "weight")
# first row of matrix A A[1, ] # first column of matrix A A[, 1]# diagonal of matrix A diag(A)

as_adjacency_matrix(g)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0 1 0 0 1 0
[2,] 1 0 1 1 0 0
[3,] 0 1 0 1 1 1
[4,] 0 1 1 0 0 0
[5,] 1 0 1 0 0 0
[6,] 0 0 1 0 0 0
Network Analysis in the Tidyverse