R igraph - convert weighted adjacency matrix to weighted edgelist

I have an nxm adjacency matrix, where (i, j) represent the estimate of the relationship between i and j. I need to convert it to the following format: i j <score1>

using the R 'igraph package and outputting it to a text file.

I can get an Eggelist, but he appears without weights. I used the following code:

library(igraph) g <- graph.adjacency(myAdjacencymatrix) get.edgelist(g)

However, he does not show weight.

+4
source share
1 answer
library(igraph)
set.seed(1)                # for reproducible example
myAdjacencyMatrix <- matrix(runif(400),nc=20,nr=20)

g  <- graph.adjacency(myAdjacencyMatrix,weighted=TRUE)
df <- get.data.frame(g)
head(df)
#   from to    weight
# 1    1  1 0.2655087
# 2    1  2 0.9347052
# 3    1  3 0.8209463
# 4    1  4 0.9128759
# 5    1  5 0.4346595
# 6    1  6 0.6547239

weighted=TRUE graph.adjacency(...), . get.data.frame(...) . what=... , , .

: , .

+17

Source: https://habr.com/ru/post/1548379/


All Articles