[R] Macro Variable in R

David Winsemius dwinsemius at comcast.net
Wed Nov 14 19:53:10 CET 2012


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

> I have over 300 variables in my table. I want to choose only a handful of
> those variables to run through many procedures. Lm(), glm() etc..i have over
> 10 procedures that i need to run those variables everytime. Those handful of
> variables can change everytime if output is satisfactory or not. 

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.

> 
> I have done this in SAS. Now i need to know how to do this in R. Any help or
> even if someone can point to a previous thread will help.

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.
-- 

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list