[R] A easy way to write formula

From: Jinsong Zhao <jszhao_at_mail.hzau.edu.cn>
Date: Sun, 27 Jul 2008 15:39:26 +0800


I have a data frame, including x1, x2, x3, and y. I use lm() to fit second-order linear model, like the following:

ft <- lm(y ~ x1 + x2 + x3 + I(x1 * x1) + I(x1 * x2) + I(x1 * x3) + I(x2 * x2) + I(x2 * x3) + I(x3 * x3), mydata)

if the independent variable number is large, the formula will be very long. Is there a easy way to write formula like the above one? I have read the R introduction, however, I don't find a easy way.

Any hints will be appreciated. Thanks,


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. Received on Sun 27 Jul 2008 - 07:41:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 27 Jul 2008 - 09:32:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive