Filippo Santi
2018-02-27 08:30:23 UTC
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.
Best,
Filippo
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.
Best,
Filippo
--
Filippo Santi
PhD Candidate in Development Economics
Filippo Santi
PhD Candidate in Development Economics