title: Possible to arrange observations in groups of N that reflect data set proportions using R?
body: <p>Are there are functions in R that arrange observations in groups of N that reflect, as closely as possible, the data set proportions of certain variables?</p>
  
  <p>For example, if I have a data set with 8 observations and two variables each with two levels with data set proportions as follows:</p>
  
  <pre><code>    Var1 Var2
  1   0.5  0.5
  2   0.5  0.5
  </code></pre>
  
  <p>Are there any functions that would enable me to optimally sample from the data set to say create groups of 2 observations that reflect the above data set proportions?</p>
  
  <p>Example data:</p>
  
  <pre><code>Data &lt;- read.table(text="   Obs Var1    Var2    
      1   1   1   
      2   1   2   
      3   2   1   
      4   2   2   
      5   1   1   
      6   1   2   
      7   2   1   
      8   2   2   ", header=T)
  </code></pre>
  
  <p>Desired Result:</p>
  
  <pre><code>Result &lt;- read.table(text=" Obs Var1    Var2    Group_ID    
      1   1   1   1   
      4   2   2   1   
      2   1   2   2   
      3   2   1   2   
      5   1   1   3   
      7   2   1   3   
      6   1   2   4   
      8   2   2   4   ", header=T)
  </code></pre>
  
  <p>Not that all groups have proportions of .5 for each level of each variable. </p>