Learn R Programming

doBy (version 4.6.13)

by-lapply: Formula based version of lapply and sapply

Description

This function is a wrapper for calling lapply on the list resulting from first calling splitBy.

Usage

lapply_by(data, formula, FUN, ...)

lapplyBy(formula, data = parent.frame(), FUN, ...)

sapply_by(data, formula, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)

sapplyBy( formula, data = parent.frame(), FUN, ..., simplify = TRUE, USE.NAMES = TRUE )

Value

A list.

Arguments

data

A dataframe.

formula

A formula describing how data should be split.

FUN

A function to be applied to each element in the splitted list, see 'Examples' below.

...

optional arguments to FUN.

simplify

Same as for `sapply`

USE.NAMES

Same as for `sapply`

Author

Søren Højsgaard, sorenh@math.aau.dk

See Also

splitBy, split_by

Examples

Run this code
fun <- function(x) range(x$uptake)
lapplyBy(~Treatment + Type, data=CO2, FUN=fun)
sapplyBy(~Treatment + Type, data=CO2, FUN=fun)

# Same as
lapply(splitBy(~Treatment + Type, data=CO2), FUN=fun)

Run the code above in your browser using DataLab