Learn R Programming

daltoolbox (version 1.1.727)

k_fold: K-fold sampling

Description

k-fold partition of a dataset using a sampling method

Usage

k_fold(obj, data, k)

Value

returns a list of k data frames

Arguments

obj

an object representing the sampling method

data

dataset to be partitioned

k

number of folds

Examples

Run this code
#using random sampling
sample <- sample_random()

# preparing dataset into four folds
folds <- k_fold(sample, iris, 4)

# distribution of folds
tbl <- NULL
for (f in folds) {
 tbl <- rbind(tbl, table(f$Species))
}
head(tbl)

Run the code above in your browser using DataLab