HI,Barry. Thanks a lot for your details reply. I have already rewritten the programs. Now it totally works. Your comment: " Note the use of comments and breaking the code up into small independent, testable functions" is really Valuable! Thanks again. Hi,David, You are right, My previous code was really horrible. Its not good to make multiple codes at the same time, sometime I feel really confused about the original one. About Your comment: "You should indent and space around more things ( <- for example). And either use = for assignment or <-, don't use both in the same bit of code.", At the moment, I am still feeling confused about the different usage of <- and =?? Now I have seperated the code into pieces, now it works. Thanks a lot. Hi Brian, Thanks for your suggestion. Seems the error is not when i call list.file. The true error is what i quote from Barry's suggestion: " name = list.files(...) for(k in 1:length(name)){ log1 = read.table(name[k],....) while(something){ k =k + 1 log1 = read.table(name[k],...) # 1 } } What will happen is that when the last file is read at point #1, the loop goes round again, k becomes more than the length of name, and it will fail at #1 again." Thanks for all your concentration. Tammy _________________________________________________________________ Drag n’ drop—Get easy photo sharing with Windows Live™ Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx [[alternative HTML version deleted]]