我在这里有点困惑,我使用以下代码提取了断开连接图的巨型组件。
function(graph) {
cl <- clusters(graph)
induced.subgraph(graph, which(cl$membership == which.max(cl$csize)))
}
但是在RStudio中运行这样的代码会给我带来常见错误,例如
is_connected(ngo.giant)
[1] TRUE
centr_clo(ngo.giant)$centralization
[1] 0.003214897
Warning message:
In centr_clo(ngo.giant) :
At centrality.c:2784 :closeness centrality is not well-defined for disconnected graphs
temp<-centr_eigen(ngo.giant,directed=T)
Warning message:
In centr_eigen(ngo.giant, directed = T) :
At centrality.c:344 :graph is directed and acyclic; eigenvector centralities will be zeros
是否有发生这种情况的原因?抱歉,如果该代码太含糊
答案 0 :(得分:2)
我刚刚收到警告,我注意到这是由于我的图形是有向的,因此某些路径只能沿一个方向行走,而某些节点却与另一个节点“分离”。
test <- data.frame(source=c('a', 'a'), target=c('b', 'c'), stringsAsFactors=FALSE)
g <- igraph::graph_from_data_frame(test, directed=TRUE)
igraph::closeness(g)
a b c
0.5000000 0.1666667 0.1666667
Warning message:
In igraph::closeness(g) :
At centrality.c:2784 :closeness centrality is not well-defined for disconnected graphs
同样,如果您在mehtod='all'
中使用参数closeness
,则您的图形将被视为无向图。