Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

71 lines (60 sloc) 1.886 kB
\title{Split data frame, apply function, and return results in a list.}
dlply(.data, .variables, .fun = NULL, ...,
.progress = "none", .drop = TRUE, .parallel = FALSE)
\item{.fun}{function to apply to each piece}
\item{...}{other arguments passed on to \code{.fun}}
\item{.progress}{name of the progress bar to use, see
\item{.data}{data frame to be processed}
\item{.variables}{variables to split data frame by, as
quoted variables, a formula or character vector}
\item{.drop}{should combinations of variables that do not
appear in the input data be preserved (FALSE) or dropped
(TRUE, default)}
\item{.parallel}{if \code{TRUE}, apply function in
parallel, using parallel backend provided by foreach}
list of results
For each subset of a data frame, apply function then
combine results into a list. \code{dlply} is similar to
\code{\link{by}} except that the results are returned in
a different format.
This function splits data frames by variables.
If there are no results, then this function will return a
list of length 0 (\code{list()}).
linmod <- function(df) {
lm(rbi ~ year, data = mutate(df, year = year - min(year)))
models <- dlply(baseball, .(id), linmod)
coef <- ldply(models, coef)
with(coef, plot(`(Intercept)`, year))
qual <- laply(models, function(mod) summary(mod)$r.squared)
Hadley Wickham (2011). The Split-Apply-Combine Strategy
for Data Analysis. Journal of Statistical Software,
40(1), 1-29. \url{}.
Other data frame input: \code{\link{daply}},
Other list output: \code{\link{alply}},
Jump to Line
Something went wrong with that request. Please try again.