[BioC] comparing two tables
Hi Tamara, No problem. ?dat3<- rbind(dat1,dat2)? #Sorry, forgot this line. A.K.
From: Tamara Simakova <tsimakova at sequoiag.com>
To: arun <smartpink111 at yahoo.com>
Sent: Thursday, May 30, 2013 12:26 PM
Subject: Re: [R] [BioC] comparing two tables
To: arun <smartpink111 at yahoo.com>
Sent: Thursday, May 30, 2013 12:26 PM
Subject: Re: [R] [BioC] comparing two tables
Hello Arun, Thanks very much for help. Indeed there is a mistake in the resulted table, it should be exactly as in your example. When I use dat3New<-with(dat3,aggregate(info,list(chr,pos,ref,alt),FUN=function(x) x)) ?colnames(dat3New)<- colnames(dat1) the R returns "dat3 is not found", but with plyr library everything works well. Thank again, Tamara? 2013/5/30 arun <smartpink111 at yahoo.com> > >Assuming that you wanted to label '1' for table1 and '4' for table2 (info column).? > >Also, not sure why chr2 row is not in the resulted table. > >dat1<- read.table(text=" > >chr??? pos??? ref??? alt >chr1??? 5??? A??? G >chr1??? 8??? T??? C >chr2??? 2??? C??? T >",sep="",header=TRUE,stringsAsFactors=FALSE) > >dat2<-read.table(text=" > >chr??? pos??? ref??? alt >chr1??? 5??? A??? G >chr1??? 7??? T??? C >chr1??? 8??? T??? A >",sep="",header=TRUE,stringsAsFactors=FALSE) >dat1$info<- 1 >?dat2$info<-4 >?dat3New<-with(dat3,aggregate(info,list(chr,pos,ref,alt),FUN=function(x) x)) >?colnames(dat3New)<- colnames(dat1) >dat3New1<-dat3New[order(dat3New$chr,dat3New$pos),] >?row.names(dat3New1)<-1:nrow(dat3New1) >?dat3New1 >#?? chr pos ref alt info >#1 chr1?? 5?? A?? G 1, 4 >#2 chr1?? 7?? T?? C??? 4 >#3 chr1?? 8?? T?? A??? 4 >#4 chr1?? 8?? T?? C??? 1 >#5 chr2?? 2?? C?? T??? 1 > >#or >library(plyr) >res<-ddply(merge(dat1,dat2,all=TRUE),.(chr,pos,ref,alt),summarize,info=list(info)) >res >#?? chr pos ref alt info >#1 chr1?? 5?? A?? G 1, 4 >#2 chr1?? 7?? T?? C??? 4 >#3 chr1?? 8?? T?? A??? 4 >#4 chr1?? 8?? T?? C??? 1 >#5 chr2?? 2?? C?? T??? 1 >names(dat3New1$info)<-NULL >?identical(dat3New1,res) >#[1] TRUE > >A.K. > > >----- Original Message ----- >From: tomkina <tsimakova at sequoiag.com> >To: r-help at r-project.org >Cc: >Sent: Thursday, May 30, 2013 4:45 AM >Subject: Re: [R] [BioC] comparing two tables > >Hello, > >I have the similar task.? I have two tables and I need to get the third >table containing data from both of them with extra column with information >of what data from which table: > >table1??? ??? ??? >chr??? pos??? ref??? alt >chr1??? 5??? A??? G >chr1??? 8??? T??? C >chr2??? 2??? C??? T > >table2??? ??? ??? >chr??? pos??? ref??? alt >chr1??? 5??? A??? G >chr1??? 7??? T??? C >chr1??? 8??? T??? A > >resulted table >chr??? pos??? ref??? alt??? info >chr1??? 5??? A??? G??? 1, 4 >chr1??? 7??? T??? C??? 4 >chr1??? 8??? T??? C??? 1 >chr1??? 8??? T??? A??? 4 > >I need all 4 columns (chr, pos, ref and alt) to be compared. I didn't find >this function in Bioconductor. I am a beginner at R and would appreciate any >help. > >Thanks, >Tamara > > > > > > >-- >View this message in context: http://r.789695.n4.nabble.com/comparing-two-tables-tp3936306p4668272.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. > >