random_sample: Creating Exploratory and Confirmatory Samples with Stratified...

Description Usage Arguments Details Value See Also Examples

View source: R/random_sample.R

Description

random_sample returns a dataframe.

Usage

1
2
random_sample(df, group, size, select = NULL, replace = FALSE,
  bothSets = FALSE)

Arguments

df

An R dataframe object

group

A character vector of the column or columns that make up the "strata"

size

The desired sample size. If size is a value less than 1, a proporortionate sample is taken from each stratum. If size is a single integer of 1 or more, that number of samples is taken from each stratum. If size is a vector of integers, the specified number of samples is taken for each stratum. In this case it is recommended that you use a named vector, e.g. 'size = c(A = 5, B = 10)' if you wanted 5 samples from 'A' and 10 from 'B'

select

This allows you to subset the groups in the sampling process. This is a list. For instance, if your group variable was "Group", with values, 'A', 'B', and 'C', you could use 'select = list(Group = c("A", C"))' to only sample from 'A' and 'C'.

replace

Should sampling be done with replacement?

bothSets

If 'size' is a scalar with a value less than one, should both sets be returned? Use 'bothSets = TRUE' to return both exploratory and confirmatory samples

Details

This function is a slightly modified version of Ananda Mahto's 'stratified' gist (https://gist.github.com/mrdwab/6424112). Primary use is to generate exploratory and confirmatory samples, with the size = .5, and bothsets = TRUE.

Value

If bothSets is TRUE, a list of length two, with each entry being an R dataframe object; otherwise, an R dataframe object.

See Also

scoring, stratified_norm

Examples

1
2
3
4
5
## Not run: 
 data(Cowles, package = "car")
 dat <- random_sample(Cowles, group = c("sex", "volunteer"), size = .5, bothSets = TRUE)

## End(Not run)

mattsigal/mmisc documentation built on May 21, 2019, 1:26 p.m.