powered by
Samples within each class separately
Class.sample(labels, nsam)
Vector of labels to convert into factor
Number of samples to take from each class
Logical vector of length equal to 'vector'
'Class.sample()' splits labels into groups in accordance with classes, and samples each of them separately.
If 'nsam' is bigger then class size, the whole class will be sampled.
# NOT RUN { (sam <- Class.sample(iris$Species, 5)) iris.trn <- iris[sam, ] iris.tst <- iris[-sam, ] # }
Run the code above in your browser using DataLab