Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

stratsample

Take a stratified sample


Description

This function takes a stratified sample without replacement from a data set.

Usage

stratsample(strata, counts)

Arguments

strata

Vector of stratum identifiers; will be coerced to character

counts

named vector of stratum sample sizes, with names corresponding to the values of as.character(strata)

Value

vector of indices into strata giving the sample

See Also

The "sampling" package has many more sampling algorithms.

Examples

data(api)
  s<-stratsample(apipop$stype, c("E"=5,"H"=4,"M"=2))
  table(apipop$stype[s])

survey

Analysis of Complex Survey Samples

v4.0
GPL-2 | GPL-3
Authors
Thomas Lumley
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.