sample_biased | R Documentation |
This function creates a data.frame which includes one or more samples taken from the original data. These samples are biased on the categories of one variable: some of the categories can be given a lower probability of inclusion than others.
sample_biased(data, x, probs, size, iterations = 1, replace = FALSE)
data |
An object of type data.frame. |
x |
A vector included in the data, which will be used to bias the sample. |
probs |
A vector of probabilities which has the same length as the number of values x can take. |
size |
The number of observations to include in each sample. |
iterations |
The number of samples to take from the data.frame. |
replace |
Should sampling be with replacement? |
The sampled data, with all columns from the
original data.frame and a prob
column indicating
the probability of inclusion of each observation. If
iterations > 1
, an iterations
column is included
to identify which iteration the observation belongs to.
CLESSN
## Not run:
# Create a 100-respondent sample where men are three
# times more likely to be included than women.
sample_biased(Data, genderWoman,
probs = c(3, 1), size = 100)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.