今天我无法对modularity函数应用apply函数,后者位于'igraph‘包中。以下是代码和结果。
> library(igraph)
> g = graph.full(2)
> modularity(g, 1:2)
[1] -0.5
> apply(FUN = modularity, MARGIN = 1, X = matrix(1:4, ncol = 2), graph = g, weights = NULL)
Error in UseMethod("modularity") :
no applicable method for 'modularity' applied to an object of class "c('integer', 'numeric')"我能够以这种方式使用apply和modularity函数,并且昨天没有出现错误消息。但是今天R抛出了上面的错误消息。有人遇到过这个问题吗?请告诉我怎么解决这个问题。谢谢!
发布于 2013-02-25 13:29:28
将图形名称更改为x应该可以。这里我还对术语进行了重新排序,但这是可选的。
apply(X = matrix(1:4, ncol = 2) , MARGIN = 1,FUN = modularity, x = g, weights = NULL)
1] -0.5 -0.5你会得到一个错误,因为模块化没有找到它的x参数,所以尝试将它应用于apply给出的列矩阵。
https://stackoverflow.com/questions/15060636
复制相似问题