diffsample {PopulateR} | R Documentation |
Sample from groups, when the sample size for each group is different
Description
Produces samples by group, enabling different sample sizes to be specified for each group. Sampling without replacement is used. While the function example is based on sampling by age, in practice sampling can be performed using any variable of choice. Only one grouping variable is used.
Usage
diffsample(people, pplage, sampledf, smplage, smplcounts, userseed = NULL)
Arguments
people |
A data frame containing individual people. |
pplage |
The variable containing the ages, in the people data frame. |
sampledf |
A data frame containing ages and sample size counts. |
smplage |
The variable containing the ages, in the sampledf data frame. |
smplcounts |
The variable containing the sample size counts, in the sampledf data frame. |
userseed |
If specified, this will set the seed to the number provided. If not, the normal set.seed() function will be used. |
Value
A data frame of people sampled according to the age sample sizes required.
Examples
SampleNeeded <- data.frame(Age = c(16, 17, 18),
NumNeeded = c(5, 10, 15))
SampledAdolescents <- diffsample(WorkingAdolescents, pplage = "Age", sampledf = SampleNeeded,
smplage = "Age", smplcounts = "NumNeeded", userseed = 4)
table(SampledAdolescents$Age)