# by {base}

### Usage

by(data, INDICES, FUN, ..., simplify = TRUE)

### Arguments

### Details

A data frame is split by row into data frames subsetted by the values of one or more factors, and function `FUN`

is applied to each subset in turn.

Object `data`

will be coerced to a data frame by the default method, *but* if this results in a 1-column data frame, the objects passed to `FUN`

are dropped to a subsets of that column.

### Values

An object of class `"by"`

, giving the results for each subset. This is always a list if `simplify`

is false, otherwise a list or array (see `tapply`

).

### Examples

require(stats) by(warpbreaks[, 1:2], warpbreaks[,"tension"], summary) by(warpbreaks[, 1], warpbreaks[, -1], summary) by(warpbreaks, warpbreaks[,"tension"], function(x) lm(breaks ~ wool, data = x)) ## now suppose we want to extract the coefficients by group tmp <- with(warpbreaks, by(warpbreaks, tension, function(x) lm(breaks ~ wool, data = x))) sapply(tmp, coef)

Documentation reproduced from R 3.0.2. License: GPL-2.