r - 对图对象快速贪婪

标签 r igraph

所以我读入了 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/

相关文章:

linux - R 程序 - igraph 包错误

r - 使用 ggraph/ggplot2 在网络图中定位节点和边

r - R中的Bron-Kerbosch算法

r - 创建具有自定义开始时间的每日 OHLC

r - 使用 `testthat` 对写入/读取文件的函数或 Fortran 错误进行单元测试

r - 如何使用中位数函数估算R中的中位数?

r - 使用 ggplot2 绘制 fitdist 图

r - 在 R 中查找给定数据的 "row wise" "Mode"

r - 创建分层网络

python - 通过 anaconda (libxml2.2.dylib) 在 OSX 10.10.5 中导入 python igraph 时出错