title: Random stratified sample from each factor levels
body: <p>I have data set with two factors: <code>Environments</code> (4 levels), <code>Individuals</code> (500 in each environment) and response variable <code>YD</code>.  As part of my analysis I have to randomly sample 100 individuals from each Environment in the following way:</p>
  
  <ol>
  <li>Same 100 individuals across all the four environments(100 individuals)</li>
  <li>Different 100 individuals from each environment  (100*4=400  individuals)</li>
  <li>Same 100 in in 2 environment and another 100 in the other 2 environments (2*100=200 individuals)</li>
  </ol>
  
  <p>I already solved this problem using several lines of code, however I hope someone will help me generate an R function to do that, which will be very useful in other situations.</p>
  
  <p>Here is example data set with similar structure: </p>
  
  <pre><code>  library(BLR)
    data (wheat)
    Data &lt;- melt(Y)
    colnames(Data) &lt;- c('Individuals','Environments','YD')
  </code></pre>