Skip to content
Prev 248016 / 398503 Next

Looping with incremented object name and increment function

This is FAQ 7.21.

The real gem in the answer there is at the end where it tells you that it is easier to just use a list.  If your fit1, fit2, fit3, and fit4 were elements in a list then you can just loop through the list elements, or even easier use the lapply function to loop through the list elements for you.

The syntax fit[ii] means that you want the ii'th element of the vector named "fit", the FAQ shows how to do what you want, but in the long run (and the medium run, and even the short run) using a list instead of separate global variables will make your life easier.