Learn R Programming

scutr (version 0.2.0)

sample_classes: Stratified index sample of different values in a vector.

Description

Stratified index sample of different values in a vector.

Usage

sample_classes(vec, tot_sample)

Value

A vector of indices that can be used to select a balanced population of values from vec.

Arguments

vec

Vector of values to sample from.

tot_sample

Total number of samples.

Examples

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