Background:
I usually use gl()
to generate "equal" number of factor levels for a set of random variables. For example, to generate 2
factor levels for 60
random variables in x
, I use the following:
x = rnorm(n = 60)
groups = gl( 2, length(x)/2 ) ## My Factor Levels
But above, doesn't allow me to produce, say, 40
factor levels for the first 40
elements in x
, and 20
factor levels for the last 20
elements in x
(i.e., "Unbalanced" (unequal) factor levels).
Question:
In base R, is there a flexible function or a strategy to produce "Unbalanced" (unequal) factor levels?