##
## Create fold
CreateFold <- function(list=NULL, data=NULL, target=NULL, fold = 10, seed = 0){
## Set random seed
set.seed(seed)
## Format input
if(is.null(list)){
list <- list()
list[["Target"]] <- target
list[["Data"]] <- data
}
## Convert to matrix if not
for(i in IterList(list)){
if(!HaveDimension(list[[i]]))
list[[i]] <- data.matrix(list[[i]])
}
## Check list name
if(is.null(names(list)))
names(list) <- as.character(seq(length(list)))
## Total data
intFirstIndex <- 1
intTotal <- nrow(list[[intFirstIndex]])
## Sample size
intSampleSize <- floor(intTotal / fold)
## Remain index
eleRemainIndex <- seq(intTotal)
## Initial resturn
listReturn <- list()
## For each fold
for(k in seq(fold)){
if(k==fold){
eleSampleIndex <- eleRemainIndex
}else{
eleSampleIndex <- sample(eleRemainIndex, intSampleSize)
eleRemainIndex <- setdiff(eleRemainIndex, eleSampleIndex)
}
## Update to return
for(i in names(list)){
listReturn[[paste(k)]][[i]] <- list[[i]][eleSampleIndex,]
}
}
return(listReturn)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.