title: Having an issue with nested for loops in R
body: <p>I am currently using apTreeshape to simulate phylogenetic trees using the "Yule-Hardy" Method. What I want to do is randomly generate between 20 and 25 different numbers for three different groupings (small, medium and large trees) and then generate about 40 trees for every random number chosen from within the grouping.</p>
  
  <p>I know how I would do this in Python of Matlab, but in R things seem to behave a bit differently.</p>
  
  <p>My thought was that if I were to generate a vector full of random numbers (one for each size grouping) and then use that to generate a vector which would basically contain all of the repeated values of each random number.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>sm_leaves&lt;-c(sample(3:50,25,replace=F));
  s_leafy&lt;-numeric();
  
  for (i in 1:length(sm_leaves)) { 
      for (j in 1:10) {
          s_leafy[j+i-1]=sm_leaves[i];
      }
  }
  </code></pre>
  
  <p>This is giving me output like:</p>
  
  <pre><code>&gt; s_leafy
  [1]  5 38  6 22 29 20 19 46  9 18 39 50 34 11 43  7  8 32 10 42 14 37
  [23] 23 13 28 28 28 28 28 28 28 28 28 28
  </code></pre>
  
  <p>But What I want is something more like:</p>
  
  <pre><code>&gt; s_leafy
  [1]  5  5  5  5  5  5  5  5  5  5 38 38 38 38 38 38 38 38 38 ... 28 28 28 28 28 28 28 28 28 28
  </code></pre>
  
  <p>My reason for doing this is merely so that I can append this vector to a data frame along with all of the randomly generated trees - I need 2000 of them, so doing this by hand ain't quite practical.</p>
  
  <p>All I have really been able to deduce from my previous attempts to solve this problem is that generally speaking while loops should be used instead of for loops, and many people have talked about using expand.grid, but I don't think that the latter is particularly useful in this case.</p>
  
  <p>Thanks for reading, I hope my problem isn't too trivial (although I wouldn't be surprised if it were).</p>