[R] Plotting multiple table automatically

Paul Hiemstra p.hiemstra at geo.uu.nl
Fri Feb 19 13:01:59 CET 2010


KennyL wrote:
> Hi All,
>
> I have a slight issue getting R to plot a series of tables automatically.
> Essentially I have a series of tables that I wish to plot. They are named
> on_2, on_3 etc. based on the file name when they were read in. I have
> filelist <- list.files() to give me list of the table names. I wish to plot
> each table, so I was thinking along some kind of for loop as below:
>
> for (i in 1:Number_Files) {
> plot(filelist[1])
> }
>
> With a few other bits a pieces, however obviously this tries to plot the
> character string in filelist, any ideas on how to get R to read the
> identically named table and plot that?
>
> Thanks,
>
> Kenny
>   
Hi Kenny,

Take a look at parse() if you want it do your way, but consider the 
following much better way. Read the files into a list first not in 
seperate R objects, something like:

list_tables = lapply(list.files(), read.table)
?lapply

and plot:

for(tab %in% list_tables) plot(tab)

cheers,
Paul

-- 
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul



More information about the R-help mailing list