[R] Adding terms to a function
    Brooke LaFlamme 
    bal44 at cornell.edu
       
    Wed Dec  6 23:46:28 CET 2006
    
    
  
Hi all,
I am running R version 2.4.0 on Windows XP. I am new and have the following question:
I have a dataset of columns named x1, x2, x3...xn. I would like to write a linear regression using lm that looks like this:
lm(y~x1+x2+x3+...+xn)
If I try to use the following code, I only get the model for y~x1+xn:
 n<-ncol(dataset)
 	 model<-lm(y~x1)
	for(i in 1:n) {
		model.new<-update(model, .~.+dataset[,i])
		            }
The purpose of this is so I can use stepAIC with model.new as the upper scope and model as the lower. 
I know there must be a simple way to do this, but I am not yet familiar with much syntax. Any help appreciated!
--
Brooke LaFlamme
Cornell University
    
    
More information about the R-help
mailing list