| 1 |
\name{By} |
| 2 |
\alias{By} |
| 3 |
\title{Conditional Evaluation of an Expression} |
| 4 |
\description{ |
| 5 |
The function \code{By} evaluates an expression within subsets of |
| 6 |
a data frame, where the subsets are defined by a formula. |
| 7 |
} |
| 8 |
\usage{ |
| 9 |
By(formula,expr,data=parent.frame()) |
| 10 |
} |
| 11 |
\arguments{ |
| 12 |
\item{formula}{an expression or (preferably) a formula |
| 13 |
containing the names of conditioning variables or factors.} |
| 14 |
\item{expr}{an expression that is evaluated for any unique combination |
| 15 |
of values of the variables contained in \code{formula}.} |
| 16 |
\item{data}{a data frame, an object that can be coerced into |
| 17 |
a data frame (for example, a \link{table}), or an environment, |
| 18 |
from which values for the variables in \code{formula} |
| 19 |
or \code{expr} are taken. |
| 20 |
} |
| 21 |
} |
| 22 |
\value{ |
| 23 |
A list of class "by", giving the results for each combination of values |
| 24 |
of variables in \code{formula}. |
| 25 |
} |
| 26 |
\examples{ |
| 27 |
|
| 28 |
berkeley <- Aggregate(Table(Admit,Freq)~.,data=UCBAdmissions) |
| 29 |
(Bres <- By(~Dept,glm(cbind(Admitted,Rejected)~Gender,family="binomial"),data=berkeley)) |
| 30 |
# The results all have 'data' components |
| 31 |
str(Bres[[1]]$data) |
| 32 |
|
| 33 |
attach(berkeley) |
| 34 |
(Bres <- By(~Dept,glm(cbind(Admitted,Rejected)~Gender,family="binomial"))) |
| 35 |
detach(berkeley) |
| 36 |
|
| 37 |
} |
| 38 |
\keyword{manip} |
| 39 |
\keyword{univar} |