title: R - sample() within for loop generates identical permutations?
body: <p>When I run a simple for loop to compute X number of permutations of a vector, the sample() function returns the same permutation for each iteration.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>options &lt;- commandArgs(trailingOnly=T)
  labels &lt;- read.table(options[2], header=F)
  holder &lt;- c()
  
  for (i in 1:options[1]){
  
      perm &lt;- sample(labels[,2:ncol(labels)], replace=F)
      perm &lt;- cbind(as.character(labels[1]), perm)
      holder &lt;- rbind(holder, perm)
  
  }
  
  write.table(holder, file=options[3], row.names=F, col.names=F, quote=F, sep='\t')
  </code></pre>
  
  <p>Is there a reason why this is so? Is there another simple way to generate say 1000 permutations of a vector?</p>
  
  <p>*<strong><em>Added after comment - a replicable example</em>*</strong></p>
  
  <pre><code>vec &lt;- 1:10
  holder &lt;-c()
  for (i in 1:5){
      perm &lt;- sample(vec, replace=F)
      holder &lt;- rbind(holder, perm)
  }
  
  &gt; holder
       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  perm    3    2    1   10    9    6    7    4    5     8
  perm    5    8    2    3    4   10    9    1    6     7
  perm   10    7    3    1    4    2    5    8    9     6
  perm    9    5    2    8    3    1    6   10    7     4
  perm    3    7    5    6    8    2    1    9   10     4
  </code></pre>
  
  <p>And this works fine! I guess I have a bug somewhere! My input is perhaps in a mess.</p>
  
  <p>Thanks,
  D.</p>
  
  <p>Thanks,
  D.</p>