Hi Hari,

You have not given examples of 'list1.bp.files.names' or
'list2.bp.files.names' and hence it is difficult to determine what the code
is trying to achieve. I will assume you want to create all pairwise merges
of the attached files. If this is indeed what you are doing, the problem is
not a problem at all, it is just that the intersection of values of the
variables geneDescription between any two files is the empty set, as is
demonstrated by the following code snippet (for each merge, TRUE is printed
if there is some overlap and FALSE is printed if there is not - a FALSE
implies concatenation in the code you have provided)

list1.bp.files.names <- list2.bp.files.names <-
c('colNamesgenesplitList1_alcoholMetobolic_genes.txt',
'colNamesgenesplitList1_cellcycle_genes.txt',
'colNamesgenesplitList2_alcoholMetabolism_genes.txt',
'colNamesgenesplitList2_cellcycle_genes.txt')

x.col.names <- y.col.names <-
c("genesymbol","geneDescription","orgSymbol","orgName")

for (i in 1:length(list1.bp.files.names)){
    temp1 <-
read.table(list1.bp.files.names[i],sep="\t",header=T,stringsAsFactors=F,quote='"')
    for (j in (i+1):length(list2.bp.files.names)){
        if(i==length(list2.bp.files.names)) break
        temp2 <-
read.table(list2.bp.files.names[j],sep="\t",header=T,stringsAsFactors=F,quote='"')
        cat(any(apply(temp1, 1, function(x, y) x['geneDescription'] %in% y,
temp2['geneDescription'])), '\n')
    }
}

A tip - there are trailing and/or leading whitespace on the variables
'geneDescription' and 'orgSymbol'. (in the latter case " RG " is a different
value to "RG"). This is probably going to give different results to what you
were expecting.

Hope this helps,
Simon Knapp

On Wed, Jan 13, 2010 at 8:48 AM, Harikrishnadhar <hari.bombex@gmail.com>wrote:

> Hi Jim,
>
> I am want to merge two files into one file :
>
> Here is my code . But the problem with this is that I am getting the 2nd
> file appended to the first when i write temp3 in my code to the text file.
> I
> am not sure what mistake I am doing .
>
> also find the test files to run the code .
>
> Please help me with this !!!!!!!!!!!!!!!!!!!!!!!
>
> temp1 <- NULL
> temp2 <- NULL
> x.col.names <-c("genesymbol","geneDescription","orgSymbol","orgName")
> y.col.names <- c("genesymbol","geneDescription","orgSymbol","orgName")
> for (i in 1:length(list1.bp.files.names)){
>    temp1 <-
>
> read.table(list1.bp.files.names[i],sep="\t",header=T,stringsAsFactors=F,quote="\"")
>  for (j in 1:length(list2.bp.files.names)){
>     temp2 <-
>
> read.table(list2.bp.files.names[j],sep="\t",header=T,stringsAsFactors=F,quote="\"")
>    temp3 <- merge(temp1,temp2,by.x = x.col.names,by.y=y.col.names,all=T)
>    myfile<-gsub("( )", "", paste("1_",merge.bp.files.names[i],".txt"))
>    write.table(temp3,file=myfile,sep="\t",quote=FALSE,row.names=F)
>  }
>  }
> Thanks
> --Hari--
>
> ______________________________________________
> 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.
>
>

	[[alternative HTML version deleted]]

