Learn R Programming

Kmisc (version 0.2.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(...)

Arguments

...
the call you might normally supply to lapply.

Details

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

See Also

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 )

Run the code above in your browser using DataLab