Skip to contents

Assigns observations to v cross-validation folds. When strata is supplied, folds are allocated within each stratum so that binary outcomes or important groups are spread more evenly across folds.

Usage

ci_cv_folds(n, v = 5L, strata = NULL, seed = NULL)

Arguments

n

Number of observations.

v

Number of folds.

strata

Optional vector of stratum labels with length n.

seed

Optional random seed for reproducible fold allocation.

Value

An integer vector of fold ids from 1 to v.

Examples

ci_cv_folds(10, v = 3, seed = 1)
#>  [1] 1 2 1 2 3 3 3 1 1 2