rigraphadjacency-matrixsna

Adjacency matrix from edge list in R


I have an unweighted edge list which I need to convert to a symmetric matrix for futher analysis. I use igraph function graph.data.frame() to create a graph object. Unfortunatelly I can't find a way to convert dgCMatrix to a matrix or creat a matrix right from the edge list. I'm sure there should be a simple way to do it.


Solution

  • If your graph.data.frame is GDF then you can get a sparse data matrix from

    as_adjacency_matrix(GDF)
    

    This is the dgCMatrix that you mention. But now you can just use

    as.matrix(as_adjacency_matrix(GDF))
    

    if you want the full matrix.