所以我读入了 csv 文件中的网络数据,并通过执行以下操作将其转换为图形对象
g = read.csv"somefile.csv", header = FALSE)
G = graph.data.frame(g,directed=FALSE)
fc = cluster_fast_greedy(G)
Error in cluster_fast_greedy(G) :
At fast_community.c:639 : fast-greedy community finding works only on graphs
without multiple edges, Invalid value
非常有趣的是,我尝试直接加载 graphml 版本并且可以运行 fast greedy
函数而没有错误。
我的问题是,如果我仅限于 csv 文件,我该如何在其上运行 fast_greedy 函数?
最佳答案
正如错误信息所说,
fast-greedy community finding works only on graphs without multiple edges
但是您可以使用simplify
函数移除多条边。
这是一个例子。首先,我创建了一个多边图 -
fastgreedy.community
失败。但是简化之后,它起作用了。
set.seed(1234)
g = erdos.renyi.game(12, 0.3)
g = add_edges(g, c(1,5, 7,10))
fastgreedy.community(g)
Error in .Call("R_igraph_community_fastgreedy", graph, as.logical(merges), :
At fast_community.c:553 : fast-greedy community finding works
only on graphs without multiple edges, Invalid value
g = simplify(g)
fastgreedy.community(g)
IGRAPH clustering fast greedy, groups: 2, mod: 0.26
+ groups:
$`1`
[1] 1 3 4 5 9 10 11
$`2`
[1] 2 6 7 8 12
关于r - 对图对象快速贪婪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52263609/