Skip to content
Prev 310803 / 398506 Next

Macro Variable in R

On Nov 13, 2012, at 6:06 PM, SASandRlearn wrote:

            
How do you represent those variables? Are they only going to appear on the RHS of hte formula? If the LHS of the formula, say 'outcome', will remain the same and the variable names can be presented in a character vector drawn from a list, combvecs, you could do something like this:

reslist <- list()
for (vec in combvecs) {
      res1 <- lm(outcome ~ . , data=dat_table[ , c("outcome", vec) ]
      res2 <- glm(outcome ~ . , data=dat_table[ , c("outcome", vec) ]
      reslist <-c( reslist, list(res1, res2) )

You really should be offering test cases that resemble the structure of your problem.
There are many threads that demonstrate how to use the formula() and as.formula() functions. The Posting Guide gives pointers on searching the Archives. You should also note that Nabble is not Rhelp and that your continued failure to include context will probably result in longer waits for replies than you might experience.