Given R function auto (below), I was wondering if it might be possible that from the second run of the for loop output of ps be used a
Let me try to give an answer.
So, firstly, I thought, that you need finite state automata function. This approach needs to use environment usage in which you need to store state and values for your functions call.
But, you need only make choice based on your cycle index value.
It's much easier, because you need only switch operator and nothing more.
auto <- function(n, dat, n.loop){
x <- 0.1;
for(i in 1:n.loop){
val <- switch(i, dbeta(x, 1, 1), dbinom(dat, n, x), dbeta(x, 1, 1)*dbinom(dat, n, x))
print(val);
}
}
auto(n = 100, dat = 55, n.loop = 3)
I have 2 questions which should reorganize code well.
1) What is an x value which you use in auto? This is not an argument in your code, so, you should determine value of x in auto directly. Maybe is this an argument?
2) What value does your function need to return as a value?
So, x <- 0.1 and print(val) were added for checking code execution.