Rev 85953 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/gl.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2013 R Core Team% Distributed under GPL 2 or later\name{gl}\alias{gl}\title{Generate Factor Levels}\description{Generate factors by specifying the pattern of their levels.}\usage{gl(n, k, length = n*k, labels = seq_len(n), ordered = FALSE)}\arguments{\item{n}{an integer giving the number of levels.}\item{k}{an integer giving the number of replications.}\item{length}{an integer giving the length of the result.}\item{labels}{an optional vector of labels for the resulting factorlevels.}\item{ordered}{a logical indicating whether the result should beordered or not.}}\value{The result has levels from \code{1} to \code{n} with each valuereplicated in groups of length \code{k} out to a total length of\code{length}.\code{gl} is modelled on the \emph{\I{GLIM}} function of the same name.}\seealso{The underlying \code{\link{factor}()}.}\examples{## First control, then treatment:gl(2, 8, labels = c("Control", "Treat"))## 20 alternating 1s and 2sgl(2, 1, 20)## alternating pairs of 1s and 2sgl(2, 2, 20)}\keyword{category}\keyword{arith}