\Header{gl}{Generate Factor Levels}
\keyword{category}{gl}
\keyword{arith}{gl}
\begin{Usage}
\begin{verbatim}
gl(n, k, length = n*k, labels=1:n, ordered=FALSE)
\end{verbatim}
\end{Usage}
\begin{Value}
This function generates \texttt{\Link{factor}}s by specifying the
pattern of their levels.
The result has levels from \texttt{1} to \texttt{n}
with each value replicated in groups of length
\texttt{k} out to a total length of \texttt{length}.
Labels for the resulting factor levels can be
optionally specified with the arguments \texttt{labels}
and the factor levels can be made ordered by
specifying \texttt{ordered=TRUE}.
\texttt{gl} is modelled on the \emph{GLIM} function of the
same name.\end{Value}
\begin{SeeAlso}
the underlying \texttt{\Link{factor}(.)}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
# First control, then treatment:
gl(2,8, label=c("Ctnrl","Treat"))
# 20 alternating 1s and 2s
gl(2, 1, 20)
# alternating pairs of 1s and 2s
gl(2, 2, 20)

\end{ExampleCode}
\end{Examples}

