[R] A easy way to write formula

Jinsong Zhao jszhao at mail.hzau.edu.cn
Sun Jul 27 09:39:26 CEST 2008


Hi

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,

Jinsong



More information about the R-help mailing list