You can use substitute: something like (untested) for(i in 1:100){ form <- substitute(.~.+x[,i], list(i=i)) model <- update(model, form) ## do something useful in here } and you do not need to update unchanged arguments!
However, why are you rewriting add1.default, when there is add1.lm? On Thu, 13 Feb 2003, lun li wrote: > Dear all, > > I am trying an automatic model selection for a multiple linear regression > using function lm and update. But, I meet a problem when using update. The > problem is the function update can not update when variables as a vector(for > example,x is a matrix with 100 regression variables). The code is as below: > > > model<-lm(y~x1,singular.ok=T,na.action=na.omit) > > for(i in 1:100){ > > model<-update(model,.~.+x[,i],singular.ok=T,na.action=na.omit)} > > If the above code is represented as below, I can get the correct result. > However, I must use the loops. > > >model<-lm(y~x1,singular.ok=T,na.action=na.omit) > >model<-update(model,.~.+x[,1],singular.ok=T,na.action=na.omit) > >model<-update(model,.~.+x[,2],singular.ok=T,na.action=na.omit) > ...... > >model<-update(model,.~.+x[,100],singular.ok=T,na.action=na.omit) -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help