Hi, Alex,

Thank you very much for the coding. It is really helpful. However, this 
code itself can not solve all the problem because since there are two 
additional requirements for this task (sorry I forgot to mention on the 
first place) . 

1) the sampling have to be random
2) the last few entries (say b) have to be evenly split into the first b 
vectors.

so. based on your code I created my first Julia function and solved the 
problem. 

function k_fold!(nObs,k)
  n=sort(sample(1:nObs,nObs,replace=false))

  b=nObs % k
  a=(nObs-b)/k
  a=convert(Int16,a)
  k_fold = Array(Vector{eltype(n)},0)

  for i in 1:b
    m=sample(n, a+1,replace=false)
    push!(k_fold, m)
    n=setdiff(n,m)
  end

  for j in 1:k-b
    m=sample(n, a,replace=false)
    push!(k_fold, m)
    n=setdiff(n,m)
  end
  return k_fold
end   


Thanks again and welcome any further modification to trim this bulky code.  

Reply via email to