lapplyBy {doBy}R Documentation

Formula based version of lapply

Description

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

Usage

lapplyBy(formula, data = parent.frame(), FUN, keep.groupid = FALSE)

Arguments

formula

A formula describing how data should be split

data

A dataframe

FUN

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

keep.groupid

If TRUE, the grouping information is stored as a dataframe in an attribute called groupid.

Value

A list.

Author(s)

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

See Also

orderBy, summaryBy, transformBy, splitBy,

Examples

data(dietox)

## Calculate weekwise feed efficiency = weight gain / feed intake
dietox <- orderBy(~Pig+Time, data=dietox)
v<-lapplyBy(~Pig, data=dietox, function(d) c(NA, diff(d$Weight)/diff(d$Feed)))
dietox$FE <- unlist(v)

## Technically this is the same as
dietox <- orderBy(~Pig+Time, data=dietox)
wdata <- splitBy(~Pig, data=dietox)
v <- lapply(wdata, function(d) c(NA, diff(d$Weight)/diff(d$Feed)))
dietox$FE <- unlist(v)

[Package doBy version 4.5-13 Index]