Learn R Programming

survey (version 4.4-2)

stratsample: Take a stratified sample

Description

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

Usage

stratsample(strata, counts)

Value

vector of indices into strata giving the sample

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)

See Also

sample

The "sampling" package has many more sampling algorithms.

Examples

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

Run the code above in your browser using DataLab