Caret is a great package for a lot of utility functions and tuning in R. For example, the sampling example can be done using Caret&#x27;s createDataPartition which maintains the relative distributions of the target classes and is more &#x27;terse&#x27;.<p><pre><code>    &gt; data(iris)
    &gt; library(caret)
    &gt; data(iris)
    &gt; idx &lt;- caret::createDataPartition(iris$Species, p = 0.7, list = F)
    &gt; summary(iris$Species)
        setosa versicolor  virginica
            50         50         50
    &gt; summary(iris[idx,]$Species)
        setosa versicolor  virginica
            35         35         35</code></pre>