### simple R function to get fold ids for cross-validation
getfolds = function(nfold,n,dorand=TRUE) { ### set up fold id
## nfold: number of folds (e.g. 5 or 10)
## n: sample size
## dorand: shuffle data
   fs = floor(n/nfold) # fold size
   fid = rep(1:nfold,rep(fs,nfold))
   diff = n-length(fid)
   if(diff>0) fid=c(1:diff,fid)
   if(dorand) fid = sample(fid,n)
   return(fid)
}
