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 -- View this message in context: http://n4.nabble.com/Plotting-multiple-table-automatically-tp1561478p1561478.html Sent from the R help mailing list archive at Nabble.com.
On 02/19/2010 10:32 PM, 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? >Hi Kenny, It's a bit hard to tell without seeing the data, but I think you may have the table in text form in the file, so you probably want something like: for(i in 1:Number_files) { tabledata<-read.table(filelist[i]) plot(tabledata,...) } But the reading in will depend upon what format the data are in the files. Jim
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
Thanks to you both, Both methods work, I was trying to do what you have suggested earlier Paul, but got in a mess, thanks for the code I can see why it was all going wrong now! Kenny -- View this message in context: http://n4.nabble.com/Plotting-multiple-table-automatically-tp1561478p1561507.html Sent from the R help mailing list archive at Nabble.com.