Durden Durden - 4 months ago 17
R Question

Defining global collection of variables in R

In Stata, one can define a global like

global PETS cats dogs rabbits mice
which collects these variables in some bucket named
. One can then use this in

reg happiness $PETS

which effectively runs
reg happiness cats dogs rabbits mice
. Is there an equivalent for this in R that allows something like
m <- lm(happiness ~ PETS + other_variable)


You can use this workaround:

PETS <- c("dogs", "rabbits", "mice")
m <- lm( as.formula( paste( "happiness ~ other_variable +", paste(PETS, collapse=" + ") ) ) )