gl
Generate Patterned Factor

Description

Makes a factor with a simple, repetitive pattern of levels.

Usage

gl(n, k, length = n * k, labels = 1:n, ordered = FALSE)

Arguments

n the number of blocks.
k the number of repetitions of each level per block.
length the length of the output. Usually, this value is a multiple of n*k; otherwise, the factor ends with a partial block.
labels a vector of names for the blocks. This is typically of length n, but may be longer. It is allowed to be shorter, but that results in missing values in the output.
ordered a logical value. If TRUE, it returns an ordered factor. If FALSE (the default), it returns a factor.
Value
A factor with n levels. Each n*k block has k repetitions of the first level, then k repetitions of the second level, and so on. This block is repeated to give the requested output length.
If ordered is TRUE, gl returns an ordered factor.
See Also
factor
Examples
gl(3,4,labels=LETTERS[1:3])  
# A A A A B B B B C C C C
# Levels: A B C
gl(3,1,9,labels=c("how", "are", "you"), ordered = TRUE)
# [1] how are you how are you how are you
# Levels: how < are < you
Package base version 6.1.1-7
Package Index