set.seed(61)
x1 <- rpois(100, lambda = 5)
table(x1)
table(make_strata(x1))
set.seed(554)
x2 <- rpois(100, lambda = 1)
table(x2)
table(make_strata(x2))
# small groups are randomly assigned
x3 <- factor(x2)
table(x3)
table(make_strata(x3))
# `oilType` data from `caret`
x4 <- rep(LETTERS[1:7], c(37, 26, 3, 7, 11, 10, 2))
table(x4)
table(make_strata(x4))
table(make_strata(x4, pool = 0.1))
table(make_strata(x4, pool = 0.0))
# not enough data to stratify
x5 <- rnorm(20)
table(make_strata(x5))
set.seed(483)
x6 <- rnorm(200)
quantile(x6, probs = (0:10) / 10)
table(make_strata(x6, breaks = 10))
Run the code above in your browser using DataLab