【发布时间】:2018-01-10 16:42:22
【问题描述】:
我正在尝试从下面我的函数中的for 循环中减去每个唯一的成对 ps。为此,我首先使用combn(p, 2)找到唯一的成对ps,第二使用outer减去每个唯一的互相配对。
在这两个步骤中,我都会出错。有没有解决这个错误的办法?
prop <- function(n, yes, a, b = a){
p <- list()
for(i in 1:length(n)){
p[[i]] <- rbeta(2, a[i] + yes[i], b[i] + (n[i] - yes[i]))
}
outer(combn(p, 2), FUN = "-") # Gives Error
}
prop(n = c(10, 20, 30), yes = rep(5, 3), a = rep(1, 3))
【问题讨论】:
标签: r function for-loop combinations