by-lapply: Formula based version of lapply.

Description Usage Arguments Value Author(s) See Also Examples

Description

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

Usage

1

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.

Value

A list.

Author(s)

S<c3><b8>ren H<c3><b8>jsgaard, [email protected]

See Also

lapplyBy

Examples

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

doBy documentation built on May 1, 2019, 6:31 p.m.