今天我未能将apply
函数应用于modularity
函数,后者位于'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抛出了上面的错误信息。有人遇到这个问题吗?请告诉我怎么解决。谢谢!
将图形名称更改为x应该可以。在这里,我也对条款进行了重新排序,但这是可选的。
apply(X = matrix(1:4, ncol = 2) , MARGIN = 1,FUN = modularity, x = g, weights = NULL)
1] -0.5 -0.5
您会得到一个错误,因为模块化找不到它的x参数,所以尝试将它应用于apply
给出的列矩阵。