-2
我创建了一个函数来计算所谓的“参与系数”值,并测试了一个短名单的功能,像这样应用在两个类似的列表给出了两种不同的结果
testList<-c(568120,711503,1077594)
testResults<-(sapply(testList, function(x) participationCoefficient(x)))
这给了我:
> testResults
[,1] [,2] [,3]
[1,] 568120.0000000 711503.0000000 1077594.0000000
[2,] 0.7333333 0.8780488 0.4166667
现在,当我尝试从另一个来源
>authList<-moduleCalcs[[x]]$authId
> authList[1:5]
[1] 548114 553928 553929 556071 559044
创建一个列表,然后使用申请复nction
> testResults<-(sapply(authList, function(y) participationCoefficient(y)))
我得到
Error in provideDimnames(x) : length of 'dimnames' [1] not equal to array extent Called from: top level
所以,我试图发送一个短authList,但我仍然得到同样的错误。对于这里发生的事情我有点困惑。
而且,这里是该函数的代码,如果有必要
participationCoefficient<-function(auth){
outmod<-as.data.frame(table(subset(m2$moduleId.x,(m2$A2==auth | m2$A1==auth) & m2$moduleId.y!=m2$moduleId.x)))
deg<-nrow(subset(m2,m2$A1==auth | m2$A2==auth))
partcoef<-1-(Reduce("+",(outmod$Freq/deg)))
answer<-c(auth,partcoef)
rm(deg,outmod,partcoef)
return(answer)
}
为什么会发生这种事你知道吗?
编辑
下面是一些数据,可用于平方米。我不确定这是否是分享它的最佳方式。如果没有,请告诉我是否有其他方法。
authList
[1] 548114 553928
A2 A1 moduleId.x moduleId.y
1013122 553928 1 1
1066822 548114 1 1
548114 722690 1 1
548114 666417 1 1
548114 854300 1 1
548114 842554 1 1
548114 991715 1 1
553928 710558 1 1
553928 767591 2 1
553928 718371 1 1
553928 649043 1 1
553928 601167 1 1
553928 637192 2 1
553928 710304 1 1
553928 559044 1 1
563965 553928 1 1
571821 553928 1 1
661623 553928 1 1
682197 553928 1 1
682886 553928 1 1
683583 553928 1 1
712141 553928 1 1
716224 553928 1 1
723022 553928 1 1
851338 553928 1 1
934132 553928 1 1
995296 553928 1 1
您的错误不是[reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。你的函数使用未定义的变量'm2'。请花时间包含我们可以复制/粘贴以重新创建错误的示例。这会帮助你更容易。简化您的代码到最小量以触发错误。 – MrFlick 2014-11-23 02:12:42
查看我提供的链接中的示例[如何制作可重现的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)以获得更好的方法包括样本数据。 'dput()'比原始数据更容易处理。 – MrFlick 2014-11-23 05:50:48