using graph.adjacency() in R

岁酱吖の 提交于 2019-11-29 07:08:39

The problem seems to be due to the data-type of the matrix elements. graph.adjacency expects elements of type numeric. Not sure if its a bug.

After you do,

m <- as.matrix(dat)

set its mode to numeric by:

mode(m) <- "numeric"

And then do:

net <- graph.adjacency(m, mode = "undirected", weighted = TRUE, diag = FALSE)
> E(net)$weight
[1]  8  1 10  1 15  1  1  5  7  1
hhh

Just a small working example below, much clearer than CSV input.

library('igraph');
adjm1<-matrix(sample(0:1,100,replace=TRUE,prob=c(0.9,01)),nc=10); 
g1<-graph.adjacency(adjm1); 
plot(g1)

P.s. ?graph.adjacency has a lot of good examples (remember to run library('igraph')).

Related threads

  1. Creating co-occurrence matrix
  2. Co-occurrence matrix using SAC?
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!