I am trying to obtain an adjacency matrix from a graph object, as I have to perform some manipulation before reconverting it to a graph to obtain the statistics I need.
However, I am stuck with a dgcMatrix, as I am not able to convert it to a standard "matrix" class adjacency matrix.
undesa.overind.1990 <- graph.data.frame(edge, vertices = vert, directed = T)
undesa.overind.1990 <- set_edge_attr(undesa.overind.1990, 'weight', value = get.edge.attribute(undesa.overind.1990, 'stock_od'))
# Extracting adjacency matrix
adjac <- as_adjacency_matrix(undesa.overind.1990, edges = T, names = T, attr = 'weight')
class(adjac) #dgMatrix
I tried to convert with
However, what I get is a matrix with "the non-zero elements in the columns sorted into increasing row order", as explained by the dgCMatrix help file, rather than the adjacency matrix.
How could I solve this issue, to retrieve the adjacency matrix from my graph? I could not find any useful help online.
Best,
Filippo
--
Filippo Santi
PhD Candidate in Development Economics