快速贪婪的图形对象

问题描述 投票:0回答:1

所以我已经在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函数呢?

r igraph
1个回答
3
投票

正如错误消息所示,

快速贪婪的社区发现仅适用于没有多边的图形

但您可以使用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
© www.soinside.com 2019 - 2024. All rights reserved.