
Last chance! 50% off unlimited learning
Sale ends in
This function takes a stratified sample without replacement from a data set.
stratsample(strata, counts)
vector of indices into strata
giving the sample
Vector of stratum identifiers; will be coerced to character
named vector of stratum sample sizes, with names corresponding to the values of as.character(strata)
The "sampling" package has many more sampling algorithms.
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