问题
I'm trying to iterate a for loop many times but it's only printing out once.
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)))
}
回答1:
i think you are looking for this
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)))
}
}
来源:https://stackoverflow.com/questions/58955845/trying-to-iterate-my-function-many-times-using-i