title: Split data into train and test stratified on label
body: <p>I have a data frame (df) with two columns (Numbers and Letters). See reproducible example:</p>
  <pre><code>Numbers&lt;- c(2.370653,3.811336,5.255120, 6.501197,7.848100,9.343938,10.843479,12.164387,13.476807,14.922644,16.419281,17.664224,19.112835,20.660367,21.962732,23.213675)
  Letters&lt;-c(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;c&quot;,&quot;d&quot;,&quot;a&quot;,&quot;b&quot;,&quot;d&quot;,&quot;d&quot;,&quot;a&quot;,&quot;a&quot;,&quot;c&quot;,&quot;b&quot;,&quot;c&quot;,&quot;c&quot;,&quot;c&quot;)
  df &lt;- as.data.frame(cbind(Numbers,Letters))
  </code></pre>
  <p>I want <strong>randomly</strong> to split the data frame into two date frames of <strong>equal</strong> size and with the same number of Letters in each. I have found the stratified() function that takes a sample with 50% of each of the Letters:</p>
  <pre><code>test &lt;- stratified(df, &quot;Letters&quot;, .5)
  </code></pre>
  <p>But this is not really the same as splitting the data frame into two data frames. I do not want any of the same values from df$Numbers in the two data frames - just the same amount of df$Letters in each. Can you help me?</p>