data_sample | R Documentation |
The data_sample function in R is used to randomly sample data from a given data frame. It can be used to obtain a subset of data for further analysis or modeling.
Two basic specializations of data_sample are sample_random and sample_stratified. They provide random sampling and stratified sampling, respectively.
Data sample provides both training and testing partitioning (train_test) and k-fold partitioning (k_fold) of data.
data_sample()
returns an object of class data_sample
#using random sampling
sample <- sample_random()
tt <- train_test(sample, iris)
# distribution of train
table(tt$train$Species)
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.