Learn R Programming

shipunov (version 1.4)

Class.sample: Samples along the class labels

Description

Samples within each class separately

Usage

Class.sample(labels, nsam)

Arguments

labels

Vector of labels to convert into factor

nsam

Number of samples to take from each class

Value

Logical vector of length equal to 'vector'

Details

'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.

Examples

Run this code
# 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