Durden Durden - 1 year ago 77
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)

Answer Source

You can use this workaround:

PETS <- c("dogs", "rabbits", "mice")
m <- lm( as.formula( paste( "happiness ~ other_variable +", paste(PETS, collapse=" + ") ) ) )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download