Learn R Programming

genvar (version 0.0.1.4)

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 = NULL)

Arguments

expr

an R expression which can use any of the variable names in the current dataset

by

a variable list in either "var1 var2 var3" format or in ~var1+var2+var3 format. 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

Examples

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

Run the code above in your browser using DataLab