Skip to content

Instantly share code, notes, and snippets.

View johnjps111's full-sized avatar

John Schneider johnjps111

View GitHub Profile
@mrdwab
mrdwab / Stratified.R
Created May 21, 2011 17:06
R stratified random sampling from a data frame
stratified = function(df, group, size) {
# USE: * Specify your data frame and grouping variable (as column
# number) as the first two arguments.
# * Decide on your sample size. For a sample proportional to the
# population, enter "size" as a decimal. For an equal number
# of samples from each group, enter "size" as a whole number.
#
# Example 1: Sample 10% of each group from a data frame named "z",
# where the grouping variable is the fourth variable, use:
#