\Header{lapply}{Apply a Function Over a List}
\alias{sapply}{lapply}
\keyword{iteration}{lapply}
\keyword{list}{lapply}
\begin{Usage}
\begin{verbatim}
lapply(X, FUN, ...)
sapply(X, FUN, ..., simplify = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{X}] list (or vector for \texttt{sapply}) to be used.
\item[\texttt{FUN}] the function to be applied.
In the case of functions like \texttt{+},
\texttt{\%*\%}, etc., the function name must be quoted.
\item[\texttt{...}] optional arguments to \texttt{FUN}.
\item[\texttt{simplify}] logical; should the result be simplified to a vector
if possible?
\end{ldescription}
\end{Arguments}
\begin{Description}
\texttt{lapply} returns a list of the same length as \texttt{X}.  Each
element of which is the result of applying \texttt{FUN} to the
corresponding element of \texttt{X}.

\texttt{sapply} is a ``user-friendly'' version of \texttt{lapply} also
accepting vectors as \texttt{X}, and returning a vector or array with
\texttt{dimnames} if appropriate.\end{Description}
\begin{SeeAlso}
\texttt{\Link{apply}}, \texttt{\Link{tapply}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
x <- list(a = 1:10, beta = exp(-3:3), logic = c(T,F,F,T))
# 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)
sapply(sapply(3:9, seq), fivenum)
\end{ExampleCode}
\end{Examples}

