I am relatively new to R and programming in general and I was wondering if there is a way to put a counter inside of an if else statement in my for loop. I have the following if/else statement inside of a for loop:
if(runif(1)<min(1,r)) {
Gibbsalph[,t]=alphcandidate
} else{
Gibbsalph[,t]=Gibbsalph[,t-1]
}
Is there a way to count how many times the loop chose the "if" option (i.e. how many times Gibbsalph[,t]=alphcandidate) while proceeding through the iterations?
Thanks a lot!