Learn R Programming

CCI (version 0.3.6.1)

permute_within_strata: Stratified permutation of x within strata

Description

Permutes values of 'x' within each stratum. By default, rows with NA in 'x' or 'strata' are left unchanged to preserve alignment.

Usage

permute_within_strata(x, strata, seed = NULL, na_action = c("keep", "drop"))

Value

x_star permuted within strata.

Arguments

x

vector to permute.

strata

factor-like vector defining strata.

seed

optional seed for reproducibility.

na_action

how to handle NA rows: "keep" (default) keeps them fixed, "drop" removes them (returns shorter vector).

Examples

Run this code
set.seed(123)
x <- 1:10
strata <- rep(letters[1:2], each = 5)
x_permuted <- permute_within_strata(x, strata, seed = 123)

Run the code above in your browser using DataLab