有人解释为什么在功能为Vectorized时失败了吗?我认为Vectorization只是预先分配内存。如果我将向量化参数传递给outer
它可以正常工作,为什么我不能将其传递给任何函数?
这有效:
Fun <- function(a,b) sum(a+b)
VecFun <- Vectorize( Fun )
outer(1:3,1:3,VecFun) #works perfectly, by which I mean it runs and returns a result
这不是:
a.trial<-function(){sample(c(0,0,0,1),1,replace=T)}
a.trial.vectorized<-Vectorize(a.trial)
a.distrib<-replicate(a.trial.vectorized,10000) #has error when runs why, it follows the same pattern as the working example above
#a.distrib<-replicate(a.trial(),10000) #works without error