title: Writing the results from a nested loop into another vector in R
body: <p>I'm pretty new to R, and am struggling a bit with it. I have the following code:</p>
  
  <pre><code>repeat {
      if (t &gt; 1000) 
          break
      else {
          y1 &lt;- rpois(50, 15)
          y2 &lt;- rpois(50, 15)
          y &lt;- c(y1, y2)
          p_0y &lt;- matrix(nrow = max(y) - min(y), ncol = 1)
          i = min(y)
          while (i &lt;= max(y)) {
              p_0y[i - min(y), ] = (length(which(y1 == i))/50)
              i &lt;- i + 1
          }
          p_y &lt;- matrix(nrow = max(y) - min(y), ncol = 1)
          j = min(y)
          while (j &lt;= max(y)) {
              p_y[j - min(y), ] = (length(which(y == j))/100)
              j &lt;- j + 1
          }
          p_0yx &lt;- p_0y[rowSums(p_0y == 0) == 0]
          p_yx &lt;- p_y[rowSums(p_0y == 0) == 0]
          g = 0
          logvect &lt;- matrix(nrow = (length(p_yx)), ncol = 1)
          while (g &lt;= (length(p_yx))) {
              logvect[g, ] = (p_0yx[g])/(p_yx[g])
              g &lt;- g + 1
          }
          p_0yx %*% (log2(logvect))
          print(p_0yx %*% (log2(logvect)))
          t &lt;- t + 1
      }
  }
  </code></pre>
  
  <p>i am happy with everything up to the last line, but instead of printing the value of p_0yx%*%(log2(logvect)) to the screen i would like to store this as another vector. any ideas? i have tried doing it a similar way as in the nested loop but doesnt seem to work.</p>
  
  <p>Thanks</p>