[R] Looping of read.table and assignment

Steve Murray smurray444 at hotmail.com
Mon Mar 23 17:52:28 CET 2009

Dear all,

I am trying to read in and assign data from 50 tables in an automated fashion. I have the following code, which I created with the help of textbooks and the internet, but it only seems to read in the final data file over and over again. For example, when I type:> table_1951  I get the same values in the table as when I type> table_2000  despite the values in the source tables being different:

year <- 1951:2000
filelist <- paste("C:\\Documents and Settings\\Data\\table_",year,".txt", sep="")
# Code seems to operate successfully up to this point

for (i in filelist) {
   for (iyear in 1951:2000) {
          assign(paste("table_",iyear, sep=""),read.table(file=i, header=TRUE, sep=","))
          noquote(paste("LOADED FILE:",paste("table_",iyear, sep=""),sep=" "))

Can anyone see what I've done wrong here?

And just as an aside, as you can see, I've inserted the 'noquote' line so that when the code is running I should be able to see each file being read in - mainly as a 'checker'. Should this work as anticipated, with each line being displayed with its corresponding table number after it's been read in?

Many thanks for any help offered,


[[elided Hotmail spam]]

More information about the R-help mailing list