Learn R Programming

genvar (version 0.0.2.0)

do: Executes R code on the dataset

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

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

Run this code
# NOT RUN {
use(cars, clear=TRUE)
do(coef(lm(speed~dist)))
# }

Run the code above in your browser using DataLab