[R] appending collums in for loop

From: Who Am I? <s1008701_at_student.hsleiden.nl>
Date: Mon, 21 Mar 2011 05:36:27 -0700 (PDT)

Hoi All,

I am trying to append collums to a data frame in a for loop. I read in tables, do some processing and then write the result to a data.frame. But, the thing I want is, that the results are appended to the data frame in stead of overwriting the results of the prevous table. It has to look something like this:

After going trough the loop once:
Array 1

After going trough the loop twice:

Array 1	Array 2	
1	          1	
2	          2	
3	          3	
4	          4	
5	          5	

After going trough the loop three times:		
Array 1	Array 2	Array 3
1	           1	          1
2	           2	          2
3	           3	          3
4	           4	          4
5	           5	          5

This is my code:


_SNP_IDs.xls",sep="\t", dec=",", fill=T, header=T)

fileNames<-list.files(getwd(), pattern='_0,5 -0,51.xls') regionMatchABCDE<-data.frame()

for(i in 1:5) {

    fileName <- fileNames[i]
    newFile <- file.path(getwd(), paste(fileNames[i], "samen_0,5 -0,51.xls"))

    snpidFile<-read.table(fileNames[i],sep="\t", dec=",", fill=T, header=T)     snpidFile<-data.frame(snpidFile)
    regionMatch<-cbind(masterTable, masterTable[match(masterTable$Pos, snpidFile$Pos),])

    regionMatchABCDE<-cbind(regionMatch[,10:18]) }

write.table(regionMatchABCDE, file= "Array 0-1-2-3-4-5.xls", col.names=T, row.names=F, quote=F, sep = "\t")


View this message in context: http://r.789695.n4.nabble.com/appending-collums-in-for-loop-tp3393446p3393446.html
Sent from the R help mailing list archive at Nabble.com.

R-help_at_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.
Received on Mon 21 Mar 2011 - 13:50:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Mar 2011 - 15:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive