Rev 7002 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{lapply}\title{Apply a Function over a List or Vector}\usage{lapply(X, FUN, \dots)sapply(X, FUN, \dots, simplify = TRUE, USE.NAMES = TRUE)}\alias{lapply}\alias{sapply}\arguments{\item{X}{list or vector to be used.}\item{FUN}{the function to be applied.In the case of functions like \code{+},\code{\%*\%}, etc., the function name must be quoted.}\item{\dots}{optional arguments to \code{FUN}.}\item{simplify}{logical; should the result be simplified to a vectorif possible?}\item{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 namesalready.}}\description{\code{lapply} returns a list of the same length as \code{X}. Eachelement of which is the result of applying \code{FUN} to thecorresponding element of \code{X}.\code{sapply} is a ``user-friendly'' version of \code{lapply} alsoaccepting vectors as \code{X}, and returning a vector or array with\code{dimnames} if appropriate.}\seealso{\code{\link{apply}}, \code{\link{tapply}}.}\examples{x <- list(a = 1:10, beta = exp(-3:3), logic = c(T,F,F,T))# compute the list mean for each list elementlapply(x,mean)# median and quartiles for each list elementlapply(x, quantile, probs = 1:3/4)sapply(x, quantile)str(i39 <- sapply(3:9, seq))# list of vectorssapply(i39, fivenum)}\keyword{iteration}\keyword{list}