Reputation: 904
How do I create a variable, fold, in my analysis dataset which is assigned the values of 1:k from the createFolds
cross-validation function in caret
?
For example using the following college admissions dataset:
# Load data.
mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
folds <- createFolds(mydata$admit, k=5)
# Create variable "mydata$fold" and assign values of 1:5 to mydata$fold.
?
Upvotes: 0
Views: 3716
Reputation: 1549
you can do this with createFolds
, it has an argument list
which defaults to TRUE
giving a list of the indicies in each fold. If you change it to FALSE
the function returns a vector of the folds that each row is being assigned to.
folds <- createFolds(mydata$admit, k=5,list = FALSE)
See ?createFolds
for more details.
Upvotes: 2