Generate a factor with custom levels and repetitions.
Arguments
- labels
A character vector specifying the custom labels for the factor levels.
- nlevels
An integer or a vector of integers indicating the number of repetitions for each label. If a single integer is provided, it is recycled to match the length of
labels
. If a vector is provided, it should have the same length aslabels
.
Examples
# Example usage of the function
fct_generator(labels = c("A", "B", "C"), nlevels = 3)
#> $A
#> [1] 3
#>
#> $B
#> [1] 3
#>
#> $C
#> [1] 3
#>
#> attr(,"class")
#> [1] "fct_names"