[R] please help, iteration through a list of files and plot each one

David Lyon david_lyon3 at yahoo.com
Tue Apr 2 06:13:09 CEST 2013

I have many files in 1 directory, file names end in .txt.

Each file has 2 columns

col1 col2

2 3

3 4

4 5

5 6

I want to make a list of the file names and iterate through each plotting them in a separate file $filename\.png with the png swapped for txt.

So far I have this, can someone help fill in the blanks?

Thank You!

file_list <- list.files()
for (file in file_list){
  if (!exists("dataset")){
    dataset <- read.table(file, header=TRUE, sep="\t")
  if (exists("dataset")){
    temp_dataset <-read.table(file, header=TRUE, sep="\t")

 ######how  to plot(temp_dataset) each file and save png(file\.png)

More information about the R-help mailing list