Not sure exactly what you mean by, “ writing a table with several rows per file”.

If what you want to do is write output to an external file, adding to it as your loop progresses, then look at the functions
  sink()
  cat()
And their ‘file’ and ‘append’ arguments.

If what you want to do is append rows to a table within R, as your loop progresses, then see the
   rbind()
function.

-Don

On 1/26/11 2:51 AM, "clemens karwautz" <clemdawg@gmx.net> wrote:

I’m running a loop opening one file after another. >setwd("D:/Documents and Settings/trflp") >a<-list.files() >results.diversity<-data.frame(matrix(0,ncol=7,nrow=length(a))) >names(results.diversity)<-c("file","simpson","shannon","eveness") >x<-length(a) >for (i in 1:x){ > trflp<-read.table(a[i],header=T,sep="\t") … I was able to make a table with the results of my calculations for each file. >results.diversity$simpson[i]<-simpson >results.diversity$shannon[i]<-shannon >results.diversity$eveness[i]<-eveness >write.table(results.diversity,"diversity.txt",row.names=F,sep="\t") Now, I would be interested in writing a table with several rows per file. e.g.: file1: size abundance 37 0.0117 43 0.1566 218 0.0682 253 0.0508 412 0.0874 ... file2: size abundance 37 0.0117 45 0.1876 218 0.0682 255 0.0808 417 0.0374 ... Final table: size abundance filename 37 0.0117  file1 43 0.1566  file1 218 0.0682  file1 253 0.0508  file1 412 0.0874  file1 37 0.0117  file2 45 0.1876  file2 218 0.0682  file2 255 0.0808  file2 417 0.0374  file2 Could you give me some advise how to manage this problem? Thank you very much Clemens -- GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit gratis Handy-Flat! http://portal.gmx.net/de/go/dsl ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
925 423-1062

	[[alternative HTML version deleted]]

