Description Usage Arguments Details Value See Also Examples
View source: R/random_sample.R
random_sample
returns a dataframe.
1 2 |
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 |
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.
If bothSets is TRUE, a list of length two, with each entry being an R dataframe object; otherwise, an R dataframe object.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.