title: decimal increments in loop for R
body: <p>I would like to find the value of "p" below (which is between 0 and 1), knowing the following equations:</p>
  
  <ul>
  <li><code>RI_26 = min(IR,na.rm=FALSE)</code></li>
  <li><code>RI_min = 100-(sse*SUM/((1+p)*Dotation2017*100))^(1/p)</code></li>
  </ul>
  
  <p>where <strong>RI_26</strong> is the minimum of resources index of my 26 area. It is a constant in my case. In RI_min, <strong>sse and Dotations2017</strong> are 2 constants and <strong>p</strong> is a unknown. I know that <strong>RI_26 should be equal to RI_min</strong>.</p>
  
  <p>It would be easy to solve it, but <strong>SUM</strong> (which is present in RI_min) is as well unknown as it is a <strong>function of p</strong> as following:</p>
  
  <pre><code>`sum.function = function(p){
    SUM &lt;- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
    for(i in 1:length(Canton))
      if(IR[i] &lt; 100) {
        SUM[i] &lt;- (100-IR[i])^(1+p)*Pop[i]
        SUM[27] &lt;- SUM[27]+SUM[i]
      }
    SUM &lt;- round(SUM,0)
    return(SUM[27])
  }
  
  SUM = sum.function(p)
  </code></pre>
  
  <p>SUM returns a number (or vector 1X1). To deal with it, I would like to find the value of p that satisfied:</p>
  
  <ul>
  <li>RI_26/RI_min = 1</li>
  </ul>
  
  <p>To do so, I would like to do a loop, beginning with p = 0 and then increasing the value of p by 0.01 until it reaches 1. The loop should return the value of p_star when the constraint is True (RI_26/RI_min = 1.00).</p>
  
  <p>I don't have any idea how to do this but it could look like the following code:</p>
  
  <pre><code>p.function = function(){
  
    for(...)
      if(RI_26/RI_min = 1.000000) {
        p_star &lt;- p
  
      }
  
    return(p_star)
  }
  </code></pre>
  
  <p>So the function will return the value of p_star when RI_26/RI_min = 1.000000. What am I suppose to write in my function: p.function to increment "p" and have the result that I want? Any idea?</p>