title: R error: "number of items to replace is not a multiple of replacement length"
body: <p>I'm very new to R. My script works fine when value are set lower. I need to calculate probabilities and need at least 1,000,000 samples. My first loop returns this error:  </p>
  
  <pre><code>Error in new.matrix[i, ] &lt;- as.vector(table(million.rep[, i])) : number of items to replace is not a multiple of replacement length
  </code></pre>
  
  <p>My script:</p>
  
  <pre><code>actual.prob &lt;- c(.14, .14, .16, .13, .19, .24)
  number.in.bag &lt;- c(8,6,20,9,10,5)
  
  million.rep &lt;- replicate(1000000, sample(1:6, 58, replace= T, actual.prob))
  
  
  
  new.matrix &lt;- matrix(nrow= 1000000, ncol=6)
  # Note to other readers... the above line throws the error.
  
  for(i in 1:1000000){
  new.matrix[i,] &lt;- as.vector(table(million.rep [, i]))
  }
  
  
  y &lt;- c()
  for(i in 1:1000000){
  y[i] &lt;- sum(new.matrix[i,] == number.in.bag)
  }
  y
  sum(y == 6)
  </code></pre>