title: keep the same value of if statement in a function
body: <p>I am a beginner at R. I am trying to u create a function with an if. </p>
  
  <pre><code>a=function(l){
      if((l==0) || (l==1)){probab=c(prob_cor= round(runif(1, IQ - VAR, IQ + VAR),4),
                        prob_i= round(runif(1,0.20 - VAR , 0.20 + VAR),4)) else probab}
      &gt; l
         [,1]
    [1,]    0
    [2,]    2
    [3,]    3
    [4,]    4
    [5,]    5
    [6,]    6
    [7,]    7
    [8,]    8
    [9,]    1
   [10,]    2
  
      apply(l,2,a)
  </code></pre>
  
  <p>in this function, my first l=0. and I will get a "probab" value. for the second l, the "if statement" will be wrong, and what I want to keep the same "probab" value previously generated (when l=0) but I never get the same value. Basically, I want to change my probs only when l= 0 or 1 otherwise keep the previously generated value.  what should I do?  Thanks!</p>