如何从邻接矩阵创建 igraph 对象 [已关闭]

How to create an igraph object from an adjacency matrix [closed]

提问人:Schielonimus 提问时间:6/17/2023 最后编辑:user20650Schielonimus 更新时间:6/17/2023 访问量:44

问:


想改进这个问题吗?通过编辑这篇文章添加详细信息并澄清问题。

5个月前关闭。

我想在 R 中创建一个数据集来分析我在原始邻接矩阵中编码的社交网络。下面你会发现我使用的代码:igraph

returnees_data <- read.table(
  "Returnees_Test1.csv", 
  sep=";", stringsAsFactors=FALSE, row.names=1)

returnees_i <- graph_from_adjacency_matrix(
  returnees_data,
  mode = c("undirected"),
  weighted = TRUE,
  diag = FALSE) 

当我运行第二个命令时,R 响应

mde(x) 中的错误:不能强制将“list”对象强制键入“double”。

我尝试了该命令,但没有奏效,我找不到其他合适的解决方案......现在我不知道问题出在我的代码中还是出在我的数据中,因为以下命令起作用了:unlist()

gplot(returnees_data,
      gmode="graph",       # type of network: undirected
      mode="kamadakawai",  # how the nodes are positioned
      vertex.cex=.8,       # the size of the node shapes
      usearrows=FALSE,     #no arrows
      displaylabels=TRUE,  # to add the node labels
      label.pos=1,        # labels below the node shapes
      label.cex=.5,        # size of the node labels
      edge.col="grey70")   # color of ties 70% white

sna::degree(returnees_data, gmode="graph") 
R iGraph 邻接矩阵 SNA

评论

0赞 user20650 6/17/2023
d = as.data.frame(diag(3)); graph_from_adjacency_matrix(d,mode = c("undirected"), weighted = TRUE)graph_from_adjacency_matrix(as.matrix(d),mode = c("undirected"), weighted = TRUE)
0赞 Schielonimus 6/18/2023
我试过了,但遇到了同样的错误。
0赞 user20650 6/18/2023
你尝试了什么?从你上面的代码来看,我认为应该可以工作......或者至少不会给出相同的错误。如果这不起作用,那么您需要查看 - 它是否正确读入?您可以使用 .m = as.matrix(returnees_data)g = graph_from_adjacency_matrix(m, mode = "undirected", weighted = TRUE)returnees_datastr(returnees_data)
0赞 clp 6/18/2023
如果不了解 的内容,就不可能回答这个问题。因此,向我们展示 的结果,它们是邻接矩阵的前 10 行。returnees_datadput(returnees_data[,1:10])
1赞 Schielonimus 6/18/2023
啊,现在它起作用了......不知道我第一次做错了什么。非常感谢您的帮助!

答: 暂无答案