提问人:Schielonimus 提问时间:6/17/2023 最后编辑:user20650Schielonimus 更新时间:6/17/2023 访问量:44
如何从邻接矩阵创建 igraph 对象 [已关闭]
How to create an igraph object from an adjacency matrix [closed]
问:
我想在 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")
答: 暂无答案
下一个:获取平方网格的邻接矩阵
评论
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)
m = as.matrix(returnees_data)
g = graph_from_adjacency_matrix(m, mode = "undirected", weighted = TRUE)
returnees_data
str(returnees_data)
returnees_data
dput(returnees_data[,1:10])