Learn R Programming

genvar (version 0.0.2.0)

forval: Execute code in the datasets environment for all values of a vector, replacing a macro with the value in each iteration

Description

Execute code in the datasets environment for all values of a vector, replacing a macro with the value in each iteration

Usage

forval(values, expr, macro = "%val")

Arguments

values

the vector of values to loop over. For example, specifying 1:5 would loop over integers from 1 to 5.

expr

a quoted expression (the experession must be enclosed in quotes) to evaluate in the loop which (presumably) uses the macro expression

macro

a word to replace in the quoted expression with the values we are looping over (default: "%val")

Value

returns NULL, invisibly

Examples

Run this code
# NOT RUN {
use(cars, clear=TRUE)
listif()
forval (2:4, "gen(speed%val, speed^%val)")
listif()
# }

Run the code above in your browser using DataLab