# Create random y (numeric)
y = rnorm(200, sample(c(1, 10), 200, replace = TRUE))
# Assign folds
fold = assign.folds(y, "gaussian", nfolds = 4)
# Check that the distribution of y is similar across folds
oldpar = par(mfrow = c(2, 2))
for (i in 1:4) {
hist(y[which(fold == i)], main = paste("Fold", i), xlab = "y")
}
par(oldpar)
Run the code above in your browser using DataLab