I'm a beginner with R. I have two vectors in character format. I tried to get the intersection of these two vectors using intersect£¨£©. But there is no result. The process is below: > a<-c("CREB2¡± ,¡°ELK1¡± ,¡°ELK4¡± ,¡°MYC¡± ,¡°NR4A1¡± ,¡°FOS¡± ,¡°SRF¡± ,¡°TAU¡± ,¡°STMN1¡± ,¡°CPLA2")> a[1] "CREB2¡± ,¡°ELK1¡± ,¡°ELK4¡± ,¡°MYC¡± ,¡°NR4A1¡± ,¡°FOS¡± ,¡°SRF¡± ,¡°TAU¡± ,¡°STMN1¡± ,¡°CPLA2"> b<-c("CAMK2¡±,¡°CPKC¡±,¡°CBL¡±,¡°STAT5A¡±,¡°FAK¡±,¡°ABL1¡±,¡°JUN¡±,¡°ELK1¡±,¡°MYC")> b[1] "CAMK2¡±,¡°CPKC¡±,¡°CBL¡±,¡°STAT5A¡±,¡°FAK¡±,¡°ABL1¡±,¡°JUN¡±,¡°ELK1¡±,¡°MYC"> intersect(a,b)character(0) However when I tried intersect£¨£©with another two vectors, it works. The example is like this: > c<-c("a", "b", "e", "c", "e", "f")> c[1] "a" "b" "e" "c" "e" "f"> d<-c("a", "g", "f", "b", "e")> d[1] "a" "g" "f" "b" "e"> intersect(c,d)[1] "a" "b" "e" "f" I think something must be wrong in my way with first two vectors(a,b). Could anyone give me a kind help to tell me the reason for that? Thank you very much. Hui Xue [[alternative HTML version deleted]]
Jim Holtman
2013-Dec-04 08:00 UTC
[R] Problems with intersections between two charcter vectors
the vectors in you first example look like a long character string since I only see quote marks at the beginning and end and notbon the individual objects, but it is hard to tell since it appears to be in HTML. Sent from my iPad On Dec 4, 2013, at 1:52, "snow" <7146781 at qq.com> wrote:> I'm a beginner with R. > > I have two vectors in character format. I tried to get the intersection of these two vectors using intersect????. But there is no result. The process is below: >> a<-c("CREB2?? ,??ELK1?? ,??ELK4?? ,??MYC?? ,??NR4A1?? ,??FOS?? ,??SRF?? ,??TAU?? ,??STMN1?? ,??CPLA2")> a[1] "CREB2?? ,??ELK1?? ,??ELK4?? ,??MYC?? ,??NR4A1?? ,??FOS?? ,??SRF?? ,??TAU?? ,??STMN1?? ,??CPLA2"> b<-c("CAMK2??,??CPKC??,??CBL??,??STAT5A??,??FAK??,??ABL1??,??JUN??,??ELK1??,??MYC")> b[1] "CAMK2??,??CPKC??,??CBL??,??STAT5A??,??FAK??,??ABL1??,??JUN??,??ELK1??,??MYC"> intersect(a,b)character(0) > However when I tried intersect????with another two vectors, it works. The example is like this: >> c<-c("a", "b", "e", "c", "e", "f")> c[1] "a" "b" "e" "c" "e" "f"> d<-c("a", "g", "f", "b", "e")> d[1] "a" "g" "f" "b" "e"> intersect(c,d)[1] "a" "b" "e" "f" > I think something must be wrong in my way with first two vectors(a,b). Could anyone give me a kind help to tell me the reason for that? Thank you very much. > > > > Hui Xue > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Berend Hasselman
2013-Dec-04 08:14 UTC
[R] Problems with intersections between two charcter vectors
On 04-12-2013, at 07:52, snow <7146781 at qq.com> wrote:> I'm a beginner with R. > > I have two vectors in character format. I tried to get the intersection of these two vectors using intersect??. But there is no result. The process is below: >> a<-c("CREB2? ,?ELK1? ,?ELK4? ,?MYC? ,?NR4A1? ,?FOS? ,?SRF? ,?TAU? ,?STMN1? ,?CPLA2")> a[1] "CREB2? ,?ELK1? ,?ELK4? ,?MYC? ,?NR4A1? ,?FOS? ,?SRF? ,?TAU? ,?STMN1? ,?CPLA2"> b<-c("CAMK2?,?CPKC?,?CBL?,?STAT5A?,?FAK?,?ABL1?,?JUN?,?ELK1?,?MYC")> b[1] "CAMK2?,?CPKC?,?CBL?,?STAT5A?,?FAK?,?ABL1?,?JUN?,?ELK1?,?MYC"> intersect(a,b)character(0) > However when I tried intersect??with another two vectors, it works. The example is like this: >> c<-c("a", "b", "e", "c", "e", "f")> c[1] "a" "b" "e" "c" "e" "f"> d<-c("a", "g", "f", "b", "e")> d[1] "a" "g" "f" "b" "e"> intersect(c,d)[1] "a" "b" "e" "f" > I think something must be wrong in my way with first two vectors(a,b). Could anyone give me a kind help to tell me the reason for that? Thank you very much. >What is displayed in Apple Mail is a mess since you posted in html. It seems that some of your double quotes ? have been converted somewhere to typographic double quotes (or however they should be called). Some of your output is weird: a[1] would display ?CREB2? only and not what you show in your mail. Doing it like this using proper ascii double quotes: a<-c("CREB2" ,"ELK1" ,"ELK4" ,"MYC" ,"NR4A1" ,"FOS" ,"SRF" ,"TAU" ,"STMN1" ,"CPLA2") b<-c("CAMK2","CPKC","CBL","STAT5A","FAK","ABL1","JUN","ELK1","MYC") intersect(a,b) displays: [1] "ELK1" ?MYC" which is what you expected? Berend> > Hui Xue > [[alternative HTML version deleted]] > > ______________________________________________ > 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.