我的代码有一个小问题。这是我的代码示例。当我运行该函数时,我得到以下结果。另外,我正在使用raply()
fromplyr
包,此函数将输出作为列表数组返回。我的代码
EmpPval<-function(dat,numberOfPermutations=100,usePlyr=TRUE)
{
if(usePlyr)
{
require(plyr)
}
if(usePlyr)
{
statistic <- raply(numberOfPermutations,permdat(dat)$statistic,.progress="tk")
browser()
}
else
{
statistic <- replicate(expr=permdat(dat)$statistic,n=numberOfPermutations,
simplify=TRUE)
}
}
>statistic #this is from one iteration
[1] 0.0409457
attr(,"numerator")
[1] 0.0007954759
attr(,"denominator")
[1] 0.01942758
我的结果有属性。现在我的问题是我无法将这些值存储在变量中,我想像这样再次访问它们:
s1<-attr(statistic,"numerator")
s2<-attr(statistic,"denominator")
在permdat()
for 循环中运行。所以我将生成 100 个这样的值,并且我想存储所有 100 个统计值及其属性。我现在得到的是这样的:
>statistic ##this is after it runs in a loop
[1] 0.028793900 [2] 0.073739396 [3] 0.049136225 [4] 0.058408310 [5] 0.027253176 [6] 0.019471812 [7] 0.071434025 [8] 0.038411458 [9] 0.028921401 [10] 0.021929506..... The attribute values are not stored.
有人可以帮我吗?提前致谢。