Generate factors by specifying the pattern of their levels.
gl(n, k, length = n*k, labels = seq_len(n), ordered = FALSE)
an integer giving the number of levels.
an integer giving the number of replications.
an integer giving the length of the result.
an optional vector of labels for the resulting factor
a logical indicating whether the result should be
ordered or not.
The result has levels from 1 to n with each value
replicated in groups of length k out to a total length of
gl is modelled on the GLIM function of the same name.
The underlying factor().
## First control, then treatment:
gl(2, 8, labels = c("Control", "Treat"))
## 20 alternating 1s and 2s
gl(2, 1, 20)
## alternating pairs of 1s and 2s
gl(2, 2, 20)
Run the code above in your browser using DataCamp Workspace