Learn R Programming

Kmisc (version 0.5.0)

dapply: Apply a Function over a List

Description

A convenience function that works like lapply, but coerces the output to a data.frame if possible. We set stringsAsFactors=FALSE, and optional=TRUE, to minimize the amount of automatic coersion R might try to do.

Usage

dapply(X, FUN, ...)

Arguments

X
a vector, expression object, or a data.frame
FUN
function to be applied to each element of X.
...
optional arguments to FUN.

Details

This function is preferable to sapply or lapply when you explicitly want a data frame returned.

See Also

lapply, lapply

Examples

Run this code
dat <- data.frame(
  x = rnorm(10),
  y = rnorm(10)
)

## Calculate 0.025, 0.975 quantiles for each column in a data.frame,
## and return result as data.frame .
dapply( dat, function(x) {
  quantile(x, c(0.025, 0.975))
} )

dapply( dat, summary )
str( dapply( dat, summary ) )

Run the code above in your browser using DataLab