title: Iterate until every row of column satisfies condition
body: <p>I need to adjust one variable until it satisfies the condition that none of its rows are higher than one specific value. Here is some context:</p>
  <ol>
  <li><p>I have 2 vectors: 'a' and 'b'</p>
  </li>
  <li><p>I normalize a and b to calculate their ratio 'c' (a_norm/b_norm)</p>
  </li>
  <li><p>Every row of 'c' must not be higher than a constant 'd'. Any 'c' row that is higher than d should be transformed into d.</p>
  </li>
  <li><p>After all 'c' rows that need to are adjusted (let's call this new column c_adjusted), I must recalculate a_norm (c_adjusted*b) (note that this will not make a_norm to be normalise, so let's call it a_adjusted)</p>
  </li>
  <li><p>I normalize a_adjusted to estimate the new a_norm (a_adjusted_norm = a_adjusted/sum(a_adjusted)*100</p>
  </li>
  <li><p>I calculate again c to check if all rows satisfy the condition after the adjustment. If any is still higher than d, I have to repeat the process until the condition is satisfied. At the end I would like the final a_adjusted_norm as the final result.</p>
  </li>
  </ol>
  <p>Does anybody knows how to achieve this? Here is a reproducible example:</p>
  <pre><code>set.seed(8)
  
  #create dataframe
  
  a&lt;- runif(100, min = 0, max = 10)
  b&lt;- runif(100, min = 0, max = 10)
  a_norm &lt;- a/sum(a)*100
  b_norm &lt;- b/sum(b)*100
  
  c &lt;- a_norm / b_norm
  c_cap &lt;- 1 #C must not be higher than c_Cap
  
  df &lt;- data.frame(a_norm, b_norm, c)
  
  df &lt;- df %&gt;%
    mutate(c_adjusted = ifelse(c &gt;= c_cap, c_cap, c), #We adjust c rows that are higher than c_cap
           a_adjusted = c_adjusted*b_norm, #We calculate the adjusted a with adjusted c
           a_adjusted_norm = a_adjusted/sum(a_adjusted)*100) #Normalize adjusted a
  
  #We calculate again c to see if it matches condition
  df &lt;- df %&gt;%
    mutate(c = a_adjusted_norm/b_norm) #see if c satisfy condition after adjusting variables
  
  #If any row of C is still higher than cap, I must adjust it again and repeat the process until all rows match the condition
  </code></pre>
  <p>Thanks in advance!</p>