尝试使用 i 多次迭代我的函数
Trying to iterate my function many times using i
我尝试多次迭代 for 循环,但只打印一次。
sample_gamma <- function(alpha, beta, n, iter) {
mean_s = c()
mean_sd = c()
for(i in 1:iter){
a = rgamma(n, shape = alpha, scale = 1/beta)
return(c(mean(a), sd(a)))
}
我想你正在找这个
sample_gamma <- function(alpha, beta, n, iter) {
mean_s = c()
mean_sd = c()
for(i in 1:iter){
a = rgamma(n, shape = alpha, scale = 1/beta)
print(c(mean(a), sd(a)))
}
}
我尝试多次迭代 for 循环,但只打印一次。
sample_gamma <- function(alpha, beta, n, iter) {
mean_s = c()
mean_sd = c()
for(i in 1:iter){
a = rgamma(n, shape = alpha, scale = 1/beta)
return(c(mean(a), sd(a)))
}
我想你正在找这个
sample_gamma <- function(alpha, beta, n, iter) {
mean_s = c()
mean_sd = c()
for(i in 1:iter){
a = rgamma(n, shape = alpha, scale = 1/beta)
print(c(mean(a), sd(a)))
}
}