samp_strat: Select random sample with stratification

View source: R/mt_extra.R

samp_stratR Documentation

Select random sample with stratification

Description

Select random sample with stratification from a binary group.

Usage

samp_strat(grp, len, strat = TRUE)

Arguments

grp

a character string indicating two group information.

len

length of random selection.

strat

a logical value indicated the sampling should be stratified.

Details

multiple group is not supported at the current stage.

Value

a selected index.

Examples

cls <- iris[, 5, drop = TRUE]
cls <- cls[cls == "setosa" | cls == "versicolor"]
cls <- droplevels(cls)
ind <- samp_strat(cls, 6, strat = TRUE)
cls[ind]
ind <- samp_strat(cls, 5, strat = TRUE)
cls[ind]

wanchanglin/mtExtra documentation built on Aug. 2, 2024, 5:47 p.m.