Skip to content
Prev 30097 / 398503 Next

lm with an arbitrary number of terms

You need to paste() together a formula.  There's an example in ?formula.
Try,

n <- 10
rhs <- paste("x", 1:n, collapse = "+", sep = "")
lhs <- "y ~"
f <- as.formula(paste(lhs, rhs))

Then pass `f' into lm().

-roger
_______________________________
UCLA Department of Statistics
rpeng at stat.ucla.edu
http://www.stat.ucla.edu/~rpeng
On Wed, 2 Apr 2003, Richard Nixon wrote: