title: Divide set into two unequal, random parts
body: <p>I am writing a function that must divide the whole set into two smaller ones at random. The size of the set is to be determined by the user.
  I will try to do it this way</p>
  <pre><code>number &lt;- function(z,y,p){
  indeks &lt;-split(z$y,sample(rep(1:2), c(p, z$y-p)))
  train &lt;- z[indeks,]
  test &lt;- z [-indeks, ]
  result &lt;- list(test, train)
  list(result)
  }
  number(z=lipiec , y=VII,  p=200)
  </code></pre>
  <p>However, the following error pops up</p>
  <blockquote>
  <p>Error in sample.int(length(x), size, replace, prob) :
  cannot take a sample larger than the population when 'replace = FALSE'</p>
  </blockquote>
  <p>The structure of the file that I am trying to divide is int. and there are 574 lines. So the value 200 is not greater than the whole sample.
  I would like to get two randomly split sets, where one of them (test) will have 200 elements, and the other (train) will be the rest of the base set.
  Does anyone have any idea what I am doing wrong?</p>
  <p>*<strong><strong>EDIT</strong></strong>
  After modification I did it as follows:</p>
  <pre><code>number &lt;- function(z,y,p){
  df &lt;- as.data.frame(z$y)
  indeks &lt;-split(df, sample(nrow(df))&lt;=p)
  train &lt;- indeks$
  test &lt;- indeks$
  str(test)}
  number(z=lipiec , y=VII,  p=200)
  </code></pre>
  <p>Now I do not know what I should assign to the test and train to assign each of them one of the parts of the collection. Anyone have an idea?</p>