[R] 'loop FOR' for make plots

Don MacQueen macq at llnl.gov
Fri Mar 31 00:55:57 CEST 2006

There are undoubtedly many ways to do this.

See the get() function.

for( i in 1:10) {
   nm <- paste( 'mp',i,'.lm',sep='')
   tmp <- get( nm )
   plot(  tmp$experimental_response, fitted(tmp) )
   readline('CR to continue ')

And you may need to specify pos or envir in get()

Another way would be to put your outputs from lm in a list, which you
could do at the time you create them, instead of afterwords, as here:

lmout <- list(mp1=mp1.lm, mp2=mp2.lm, mp3=mp3.lm)
     function(ff)   {  plot(ff$experimental_response,fitted(ff)) ; 
abline(0,1)  }

I haven't tested these precisely; there may be typographical errors.


At 7:14 PM -0100 3/30/06, klebyn wrote:
>How to create plots dynamically with results of several analysis ?
>I got many outputs from lm fuction like:
>mp1.lm mp2.lm mp3.lm mp4.lm mp5.lm ...
>I'd like to make experimental versus predicted response plots of all
>in a 'for loop':
>for( i in 1:10){
>plot(  mp*i*$experimental_response, fitted( mp*i* ) ); abline(0,1)
>I tried: paste( 'mp', i, sep=''), but it don't work.
>How to make this reference?
>R-help at stat.math.ethz.ch mailing list
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA

More information about the R-help mailing list