\HeaderA{rle}{Run Length Encoding}{rle}
\aliasA{inverse.rle}{rle}{inverse.rle}
\aliasA{print.rle}{rle}{print.rle}
\keyword{manip}{rle}
\begin{Description}\relax
Compute the lengths and values of runs of equal values in a vector
-- or the reverse operation.
\end{Description}
\begin{Usage}
\begin{verbatim}
rle(x)
inverse.rle(x, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] an atomic vector for \code{rle()}; an object of class
\code{"rle"} for \code{inverse.rle()}.
\item[\code{...}] further arguments which are ignored in \R.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Missing values are regarded as unequal to the previous value, even if
that is also missing.

\code{inverse.rle()} is the inverse function of \code{rle()},
reconstructing \code{x} from the runs.
\end{Details}
\begin{Value}
\code{rle()} returns an object of class \code{"rle"} which is a list
with components:
\begin{ldescription}
\item[\code{lengths}] an integer vector containing the length of each run.
\item[\code{values}] a vector of the same length as \code{lengths} with the
corresponding values.
\end{ldescription}


\code{inverse.rle()} returns an atomic vector.
\end{Value}
\begin{Examples}
\begin{ExampleCode}
x <- rev(rep(6:10, 1:5))
rle(x)
## lengths [1:5]  5 4 3 2 1
## values  [1:5] 10 9 8 7 6

z <- c(TRUE,TRUE,FALSE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE)
rle(z)
rle(as.character(z))

stopifnot(x == inverse.rle(rle(x)),
          z == inverse.rle(rle(z)))
\end{ExampleCode}
\end{Examples}

