Here, I would like to record the R function for generating factors by specifying the pattern of their levels:
gl(n, k, length = n*k, labels = 1:n, ordered = FALSE)
# Examples
## 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)
没有评论:
发表评论