[R] metaprogramming with lm

Erik Iverson iverson at biostat.wisc.edu
Thu Nov 13 01:38:11 CET 2008

The special name "." may be used on the right side of the "~" operator, 
to stand for all the variables in a data.frame other than the response.

--John Chambers, Statistical Models in S, p. 101

So, if the y and Xi (in your case) were the only variables in mydata, then

lm(y ~ . , data = mydata)

would be of use.


June Kim wrote:
> Hello,
> Say I want to make a multiple regression model with the following expression:
> lm(y~x1 + x2 + x3 + ... + x_n,data=mydata)
> It gets boring to type in the whole independent variables, in this
> case x_i. Is there any simple way to do the metaprogramming for this?
> (There are different cases where the names of the independent
> variables might sometimes have apparent patterns or not)
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list