title: Providing wrong answer with if-else inside function on R?
body: <pre><code>myfun &lt;- function(ret,d,tau,n){
      area&lt;-0
      for(i in d) { 
          ifelse(i &lt; tau + ret, area &lt;- area + (ret-i)^n,0)
      }
      return(data.frame(area=area,tau=tau,ret=ret))
  }
  </code></pre>
  
  <p>Now   <code>myfun(c(-10,11),c(6,4,5),3,1)</code> gives the answer as <code>-45</code> and <code>18</code>.<br>
  But for <code>myfun(c(-10,-11),c(6,4,5),3,1)</code> answer is <code>0</code> and <code>0</code>. <br>
  For <code>ret= -10</code> answer should be zero which was provided only in 2nd case. <br>Where is the error for such misleading answer? <br></p>