Skip to content
Prev 22410 / 398502 Next

constructing a formula

Dear Mitchell,
At 05:52 PM 8/5/2002 -0400, Michaell Taylor wrote:
Did you really mean to regress d on predictors including d? (Note that the 
data frame a shadows a$a.)
Note that a$b appears twice on the RHS of the formula -- probably not what 
you meant.
If all of the variables on the RHS are numeric, as here, then something like
         lm(a$a ~ as.matrix(a[,ListOfVar]))
should work, where a is the data frame containing the variables in the list 
(actually a character vector).

If there are also factors on the RHS of the formula, then you could do 
something like
         lm(eval(parse(text=paste('a ~', paste(ListOfVar, collapse="+")))), 
data=a)
though someone will probably think of something simpler.

Does that do what you need?
   John

-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._