Selects whole clusters at random and returns all of their rows. The row count
follows from which clusters were picked, so there is no n; use
design_multistage() when you need to control it.
Arguments
- clusters
Column naming each row's cluster.
- n_clusters
Number of clusters to select.
- balanced
Take an equal number of rows from each selected cluster, equal to the smallest selected cluster's size.
- na_rm
Drop rows whose cluster label is
NAinstead of raising an error. WhenFALSE, missing labels are never treated as a cluster of their own.
Value
A design object, for use with draw().
Examples
df <- data.frame(id = 1:100, site = rep(paste0("s", 1:10), each = 10))
unique(draw(df, design_cluster("site", n_clusters = 3), seed = 1)$site)
#> [1] "s4" "s7" "s9"