title: Counter in an if/else statement using R?
body: <p>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:</p>
  
  <pre><code>if(runif(1)&lt;min(1,r)) {
  Gibbsalph[,t]=alphcandidate
  } else{
  Gibbsalph[,t]=Gibbsalph[,t-1]
  }
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks a lot!</p>