gf | R Documentation |
Insert vectors with variable names into { } placeholder in a formula and collapse vectors with +.
gf(
form,
values = list(),
enclos = parent.frame(),
as.formula = TRUE,
form.env = parent.frame(),
collapse = " + "
)
form |
A formula or string of a formula. E.g. |
values |
A named list containing the vectors of variable names. If empty the enclosing environment will be searched. |
enclos |
the enclosing environment in which the vectors with variable names will be taken if not provided by values. By default the calling enviornment. |
as.formula |
if |
form.env |
The environment assigned to the returned formula. By default the calling environment. |
collapse |
how shall variables in a vector be collapsed. Default |
An adaption of the glue
function specialized to build
regression formulas from variable names stored in vectors.
# Assume we want to estimate a demand function
# using ivreg
contr = c("x1","x2","x3") # exogenous control variables
instr = c(contr, "z1","z2") # instruments
# Replace {contr} and {instr} in formula
gf(q ~ p + {contr} | {instr})
# You could also provide the formula as string
gf("q ~ p + {contr} | {instr}")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.