dapply: Apply a Function over a List

Description Usage Arguments Details See Also Examples

View source: R/misc.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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 ) )

Kmisc documentation built on May 29, 2017, 1:43 p.m.

Related to dapply in Kmisc...