Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

By

Conditional Evaluation of an Expression


Description

The function By evaluates an expression within subsets of a data frame, where the subsets are defined by a formula.

Usage

By(formula,expr,data=parent.frame())

Arguments

formula

an expression or (preferably) a formula containing the names of conditioning variables or factors.

expr

an expression that is evaluated for any unique combination of values of the variables contained in formula.

data

a data frame, an object that can be coerced into a data frame (for example, a table), or an environment, from which values for the variables in formula or expr are taken.

Value

A list of class "by", giving the results for each combination of values of variables in formula.

Examples

berkeley <- Aggregate(Table(Admit,Freq)~.,data=UCBAdmissions)
(Bres <- By(~Dept,glm(cbind(Admitted,Rejected)~Gender,family="binomial"),data=berkeley))
# The results all have 'data' components
str(Bres[[1]]$data)

attach(berkeley)
(Bres <- By(~Dept,glm(cbind(Admitted,Rejected)~Gender,family="binomial")))
detach(berkeley)

memisc

Management of Survey Data and Presentation of Analysis Results

v0.99.27.3
GPL-2
Authors
Martin Elff (with contributions from Christopher N. Lawrence, Dave Atkins, Jason W. Morgan, Achim Zeileis)
Initial release
2020-11-18

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.