Learn R Programming

daltoolbox (version 1.3.767)

sample_groups: Group sampling

Description

Sample entire groups defined by a categorical attribute. In sampling theory, this design is known as cluster sampling (also called one-stage cluster sampling or sampling by groups). The groups are assumed to be pre-defined in the data; this function does not infer groups with clustering algorithms such as k-means.

Usage

sample_groups(attribute, n_groups)

Value

returns an object of class sample_groups

Arguments

attribute

group-defining attribute name

n_groups

number of groups to sample

Examples

Run this code
data(iris)
sc <- sample_groups("Species", n_groups = 2)
iris_sc <- transform(sc, iris)
table(iris_sc$Species)

Run the code above in your browser using DataLab