Stratify: Stratified Sampling

Description Usage Arguments Examples

Description

Sample row values of a data frame conditional to some strata attributes.

Usage

1
2
Stratify(.data, group, size, select = NULL, replace = FALSE,
  both.sets = FALSE)

Arguments

.data

the data frame.

group

the grouping factor, may be a list.

size

the sample size.

select

if sampling from a specific group or list of groups.

replace

should sampling be with replacement?

both.sets

if TRUE, both 'sample' and '.data' are returned.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
data(pollster2008)

# Let's take a 10% sample from all -PollTaker- groups in pollster2008
 Stratify(pollster2008, "PollTaker", 0.1)

 # Let's take a 10% sample from only 'LV' and 'RV' groups from -Pop- in pollster2008
 Stratify(pollster2008, "Pop", 0.1, select = list(Pop = c("LV", "RV")))

 # Let's take 3 samples from all -PollTaker- groups in pollster2008,
 # specified by column 1
Stratify(pollster2008, group = 1, size = 3)

# Let's take a sample from all -Pop- groups in pollster2008, where we
# specify the number wanted from each group
Stratify(pollster2008, "Pop", size = c(3, 5, 4))

# Use a two-column strata (-Pop- and -PollTaker-) but only interested in
# cases where -Pop- == 'LV'
Stratify(pollster2008, c("Pop", "PollTaker"), 0.15, select = list(Pop = "LV"))

SciencesPo documentation built on May 29, 2017, 9:28 p.m.