sample_groups: Group sampling

View source: R/trans_sample_groups.R

sample_groupsR Documentation

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)

Arguments

attribute

group-defining attribute name

n_groups

number of groups to sample

Value

returns an object of class sample_groups

Examples

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

daltoolbox documentation built on May 14, 2026, 9:06 a.m.