title: Error in the output file of a for loops in r
body: <p>I'm trying to perform a resample of a list using the for loops in R for generating a data frame that records the output of each trial.  </p>
  
  <p>I get the for loops to work without error, but I am sure I am making a mistake somewhere as I should not be getting the result for the jth entry that I get as possible outcomes.</p>
  
  <p>Here's how I am generating my list:</p>
  
  <pre><code>set1=rep(0,237)  # repeat 0's 237 times 
  set2=rep(1,33) # repeats 1s 33 times
  aa=c(set1,set2) # put the two lists together
  table(aa) # just a test count to make sure I have it set up right 
  </code></pre>
  
  <p>Now I want to take a random sample set of size j out of aa and record how many 0's and 1's I get each time I perform this task (let's say n number of trials).</p>
  
  <p>Here's how I have set it up:</p>
  
  <pre><code>n=1000
  j=27
  output=matrix(0,nrow=2,ncol=n)
  for (i in 1:n){
      trial&lt;-sample(aa,j,replace=F)
      counts=table(trial)
      output[,i]=counts
  }
  </code></pre>
  
  <p>Checking the output,</p>
  
  <pre><code>  table(output[1,])
        # 17  18  19  20  21  22  23  24  25  26  27 
           1   1   9  17  46 135 214 237 205 111  24 
  
    table(output[2,])
       # 1   2   3   4   5   6   7   8   9  10  27 
         111 205 237 214 135  46  17   9   1   1  24 
  </code></pre>
  
  <p>I do not think I am getting the right answer from the distribution for the <code>j</code>th value (in this case 27) for either of the expected number of 0's or 1's (should be close to 0 as oppose to the high number it returns).</p>
  
  <p>Any suggestions as to where I am going wrong would be greatly appreciated.</p>