do: Executes R code on the dataset

Description Usage Arguments Value Examples

View source: R/do.r

Description

Executes an R expression using variables from the dataset, possibly separately for each level of a given varlist (like the by prefix in Stata).

Usage

1
do(expr, by)

Arguments

expr

an R expression which can use any of the variable names in the current dataset. It can be quoted or unquoted.

by

a variable list in "var1 var2 var3" format or, if a single variable, it can be unquoted (var1). The R expression will be applied separately for the data subsetted to each level of the variable list.

Value

returns whatever the expression expr returns. If by is specified, it will be a list of the result for applying the expression to each section of the data

Examples

1
2
use(cars, clear=TRUE)
do(coef(lm(speed~dist)))

genvar documentation built on Jan. 21, 2020, 9:07 a.m.