Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Michael Costello
> Sent: Friday, January 21, 2011 9:43 AM
> To: r-help at r-project.org
> Subject: [R] Looping with incremented object name and increment
> function
>
> Folks,
>
> I am trying to get a loop to run which increments the object name as
> part of
> the loop. Here "fit1" "fit2" "fit3" and "fit4" are linear regression
> models
> that I have created.
>
> > for (ii in c(1:4)){
> + SSE[ii]=rbind(anova(fit[ii])$"Sum Sq")
> + dfe[ii]=rbind(summary(fit[ii])$df)
> + }
> Error in anova(fit[ii]) : object 'fit' not found
>
> Why isn't it looking for object 'fit1' instead of 'fit'?
>
> The idea is that it would store in SSE1 the Sum Sq of the model fit1,
> and so
> on for the other 3 models. Is there a way to do this in R? I can do
> it in
> Stata, but am only somewhat knowledgeable in R.
>
> -Michael
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.