powered by
Stratified index sample of different values in a vector.
sample_classes(vec, tot_sample)
A vector of indices that can be used to select a balanced population of values from vec.
vec
Vector of values to sample from.
Total number of samples.
vec <- sample(1:5, 30, replace = TRUE) table(vec) sample_ind <- sample_classes(vec, 15) table(vec[sample_ind])
Run the code above in your browser using DataLab