\Header{lapply}{Apply a Function over a List or Vector}
\alias{sapply}{lapply}
\keyword{iteration}{lapply}
\keyword{list}{lapply}
\begin{Description}\relax
\code{lapply} returns a list of the same length as \code{X}.  Each
element of which is the result of applying \code{FUN} to the
corresponding element of \code{X}.

\code{sapply} is a ``user-friendly'' version of \code{lapply} also
accepting vectors as \code{X}, and returning a vector or array with
\code{dimnames} if appropriate.\end{Description}
\begin{Usage}
\begin{verbatim}
lapply(X, FUN, ...)
sapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{X}] list or vector to be used.
\item[\code{FUN}] the function to be applied.
In the case of functions like \code{+},
\code{\%*\%}, etc., the function name must be quoted.
\item[\code{...}] optional arguments to \code{FUN}.
\item[\code{simplify}] logical; should the result be simplified to a vector
if possible?
\item[\code{USE.NAMES}] logical; if \code{TRUE} and if \code{X} is character,
use \code{X} as \code{\Link{names}} for the result unless it had names
already.
\end{ldescription}
\end{Arguments}
\begin{SeeAlso}\relax
\code{\Link{apply}}, \code{\Link{tapply}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
x <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE))
# compute the list mean for each list element
lapply(x,mean)
# median and quartiles for each list element
lapply(x, quantile, probs = 1:3/4)
sapply(x, quantile)
str(i39 <- sapply(3:9, seq))# list of vectors
sapply(i39, fivenum)
\end{ExampleCode}
\end{Examples}

