title: How to construct a for loop if I need a different ending in different cases?
body: <p>I have a task to construct a data frame with a given rules:</p>
  
  <p>There is a vector like <code>V&lt;-c(10, 20, 15, 22, 60)</code>. I need length (V) columns and <code>max(V)</code> rows. For each i-column I need V[i] values. For example for first column I need 10 non-zero values and 50 zeros, for the second col I need 20 non zero values and 40 zeros. For this issue I run a code:</p>
  
  <pre><code>EL&lt;-matrix( rep( 0, len=3400), nrow = 8)
  for (i in 1:8){
    for (j in 1:(n[i])){
      EL[j,i]&lt;-100*p[i]*LGD[i]
    }
  }
  </code></pre>
  
  <p>It shows an error </p>
  
  <blockquote>
    <p>Error in [&lt;-(<em>tmp</em>, j, i, value = 100 * p[i] * LGD[i]) :<br>
    subscript out of bounds`. Should I do an ifelse loop or there is any possible ways to solve this problem&amp;</p>
  </blockquote>