Description Usage Arguments Value Examples
View source: R/stratified_norm.R
This function creates a stratified random sample, given an arbitrary number of factors and levels within those factors.
1 2 | stratified_norm(dat, strata, observations = 0, return.grid = FALSE,
full.data = FALSE, full.data.id = "sampled")
|
dat |
An R data.frame object |
strata |
character; a named vector indicating the strata variables |
observations |
numeric; number of cases to sample from each strata |
return.grid |
logical; return grid of factor combintions? |
full.data |
logical; return the original dataset with a new logical variable (named from 'full.data.id') indicating whether the row was selected |
full.data.id |
a string pertaining the variable name used when 'full.data=TRUE' |
An R data.frame object, either pertaining to a grid of factor combinations or the stratified sample
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## Not run:
dat <- data.frame(Gender=sample(c("Male", "Female"), size = 1500, replace = TRUE),
AgeGroup=sample(c("18-39", "40-49", "50+"), size = 1500, replace = TRUE),
Relationship=sample(c("Direct", "Manager", "Coworker", "Friend"),
size = 1500, replace = TRUE),
X=rnorm(n=1500, mean=0, sd=1),
Y=rnorm(n=1500, mean=0, sd=1),
Z=rnorm(n=1500, mean=0, sd=1))
strata = c("Gender", "AgeGroup", "Relationship")
stratified_norm(dat, strata, return.grid=TRUE)
test <- stratified_norm(dat, strata, counts = 5, return.grid=FALSE)
head(test)
stratified_norm(dat, strata, counts = 5, full.data=TRUE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.