title: stratified 10 fold cross validation
body: <p>I have made a start to create some training and test sets using 10 fold crossvalidation for an artificial dataset:</p>
  
  <pre><code>rows &lt;- 1000
  
  X1&lt;- sort(runif(n = rows, min = -1, max =1))
  occ.prob &lt;- 1/(1+exp(-(0.0 + 3.0*X1)))
  true.presence &lt;- rbinom(n = rows, size = 1, prob = occ.prob)
  
  # combine data as data frame and save
  data &lt;- data.frame(X1, true.presence)
  
  id &lt;- sample(1:10,nrow(data),replace=TRUE)
  ListX &lt;- split(data,id) 
  fold1 &lt;- data[id==1,] 
  fold2 &lt;- data[id==2,] 
  fold3 &lt;- data[id==3,] 
  fold4 &lt;- data[id==4,] 
  fold5 &lt;- data[id==5,] 
  fold6 &lt;- data[id==6,] 
  fold7 &lt;- data[id==7,] 
  fold8 &lt;- data[id==8,] 
  fold9 &lt;- data[id==9,] 
  fold10 &lt;- data[id==10,] 
  
  trainingset &lt;- subset(data, id %in% c(2,3,4,5,6,7,8,9,10))
  testset &lt;- subset(data, id %in% c(1))
  </code></pre>
  
  <p>I am just wondering whether there are easier ways to achieve this and how I could perform stratified crossvalidation which ensures that the class priors (true.presence) are roughly the same in all folds?</p>