[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Converting Igraph object to adjacency matrix of class "matrix"

From: Filippo Santi
Subject: [igraph] Converting Igraph object to adjacency matrix of class "matrix"
Date: Tue, 27 Feb 2018 09:30:23 +0100

Hello Everyone, 

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. 

Below the code I am using:

# Creating network from edgelist
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 

as(adjac, "matrix")

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.



Filippo Santi
PhD Candidate in Development Economics

reply via email to

[Prev in Thread] Current Thread [Next in Thread]