Sorry, maybe it's easy but I haven't found anything useful: how can I obtain a list C that contains all the members in the list B that are not in list A? This are lists of nanes, not numbers! Thank you Gabriele Zoppoli, MD Ph.D. Fellow, Experimental and Clinical Oncology and Hematology, University of Genova, Genova, Italy Guest Researcher, LMP, NCI, NIH, Bethesda MD Work: 301-451-8575 Mobile: 301-204-5642 Email: zoppolig at mail.nih.gov
On Feb 12, 2010, at 5:06 PM, Zoppoli, Gabriele (NIH/NCI) [G] wrote:> Sorry, maybe it's easy but I haven't found anything useful: > > how can I obtain a list C that contains all the members in the list > B that are not in list A? This are lists of nanes, not numbers!> A <- list("a", "b" , "c") > B <- list("a", "b" , "c", "d") > C <- setdiff(A,B) > C list() > C <- setdiff(B, A) > C [[1]] [1] "d" -- David Winsemius, MD Heritage Laboratories West Hartford, CT
> a<-list('a', 'b', 'c') > b<-list('c', 'd', 'e') > c<-intersect(a,b) > c[[1]] [1] "c" Is this what you want? Cheers Iain --- On Fri, 12/2/10, Zoppoli, Gabriele (NIH/NCI) [G] <zoppolig at mail.nih.gov> wrote:> From: Zoppoli, Gabriele (NIH/NCI) [G] <zoppolig at mail.nih.gov> > Subject: [R] logical operations with lists > To: "r-help at r-project.org" <r-help at r-project.org> > Date: Friday, 12 February, 2010, 22:06 > Sorry, maybe it's easy but I haven't > found anything useful: > > how can I obtain a list C that contains all the members in > the list B that are not in list A? This are lists of nanes, > not numbers! > > Thank you > > > Gabriele Zoppoli, MD > Ph.D. Fellow, Experimental and Clinical Oncology and > Hematology, University of Genova, Genova, Italy > Guest Researcher, LMP, NCI, NIH, Bethesda MD > > Work: 301-451-8575 > Mobile: 301-204-5642 > Email: zoppolig at mail.nih.gov > ______________________________________________ > 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. >
This is probably not the best way, but (assuming you had vectors and not lists, since I'm not sure what your list looks like): C <- B[which(B %in% A ==FALSE)] Regards, Jonathan On Fri, Feb 12, 2010 at 5:06 PM, Zoppoli, Gabriele (NIH/NCI) [G] <zoppolig at mail.nih.gov> wrote:> Sorry, maybe it's easy but I haven't found anything useful: > > how can I obtain a list C that contains all the members in the list B that are not in list A? This are lists of nanes, not numbers! > > Thank you > > > Gabriele Zoppoli, MD > Ph.D. Fellow, Experimental and Clinical Oncology and Hematology, University of Genova, Genova, Italy > Guest Researcher, LMP, NCI, NIH, Bethesda MD > > Work: 301-451-8575 > Mobile: 301-204-5642 > Email: zoppolig at mail.nih.gov > ______________________________________________ > 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. >
sorry, misread your post try this...> c<-setdiff(a,b) > c[[1]] [1] "a" [[2]] [1] "b" for a list C that contains all the members in the list B that are not in list A --- On Fri, 12/2/10, Zoppoli, Gabriele (NIH/NCI) [G] <zoppolig at mail.nih.gov> wrote:> From: Zoppoli, Gabriele (NIH/NCI) [G] <zoppolig at mail.nih.gov> > Subject: [R] logical operations with lists > To: "r-help at r-project.org" <r-help at r-project.org> > Date: Friday, 12 February, 2010, 22:06 > Sorry, maybe it's easy but I haven't > found anything useful: > > how can I obtain a list C that contains all the members in > the list B that are not in list A? This are lists of nanes, > not numbers! > > Thank you > > > Gabriele Zoppoli, MD > Ph.D. Fellow, Experimental and Clinical Oncology and > Hematology, University of Genova, Genova, Italy > Guest Researcher, LMP, NCI, NIH, Bethesda MD > > Work: 301-451-8575 > Mobile: 301-204-5642 > Email: zoppolig at mail.nih.gov > ______________________________________________ > 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. >
these are vectors in R not lists try: a<-c('a', 'b', 'c')#first vector (like A)> a[1] "a" "b" "c" b<-c('c', 'd', 'e')#second vector (like B)> b[1] "c" "d" "e" c<-setdiff(b,a)# all those in B but not A> c[1] "d" "e" cheers iain --- On Fri, 12/2/10, Zoppoli, Gabriele (NIH/NCI) [G] <zoppolig at mail.nih.gov> wrote:> From: Zoppoli, Gabriele (NIH/NCI) [G] <zoppolig at mail.nih.gov> > Subject: Re: [R] logical operations with lists > To: "r-help at r-project.org" <r-help at r-project.org> > Date: Friday, 12 February, 2010, 22:57 > I'm sorry but here's what I get: > > > A[1:10,] >? [1] UQCRC1 IDH3B? PDHA1? SUCLA2 COX5B? > SDHB???SDHA???MDH2???DLD? > ? COQ7 > > > dim(A) > [1] 1013? ? 1 > > > B[1:10,] >? [1] 3.8-1.2 3.8-1.3 3.8-1.4 3.8-1.5 5-HT3c2 A1BG? > ? A1CF? ? > A2BP1???A2LD1???A2M??? > > > dim(B) > [1] 55546? ???1 > > > C<-rbind(A,B) > > dim(C) > [1] 56559? ???1 > > > D <- C[which(C %in% A ==FALSE)] > > dim(D) > [1] 56559? ???0 > > and so with any other proposed method. > > I imported the list A and B this way: > > > > A<-as.vector(read.delim("E:/A.txt",sep="\t",header=FALSE)) > > and then removed the redundant rows with: > > > A<-unique(A) > > Guess I'm doing something really wrong here... Sorry for > the inexperience, I'm trying to improve... > > > > > > Gabriele Zoppoli, MD > Ph.D. Fellow, Experimental and Clinical Oncology and > Hematology, University of Genova, Genova, Italy > Guest Researcher, LMP, NCI, NIH, Bethesda MD > > Work: 301-451-8575 > Mobile: 301-204-5642 > Email: zoppolig at mail.nih.gov > ________________________________________ > From: jbreichel at gmail.com > [jbreichel at gmail.com] > On Behalf Of Jonathan [jonsleepy at gmail.com] > Sent: Friday, February 12, 2010 5:21 PM > To: Zoppoli, Gabriele (NIH/NCI) [G] > Cc: r-help at r-project.org > Subject: Re: [R] logical operations with lists > > This is probably not the best way, but (assuming you had > vectors and > not lists, since I'm not sure what your list looks like): > > C <- B[which(B %in% A ==FALSE)] > > Regards, > Jonathan > > > On Fri, Feb 12, 2010 at 5:06 PM, Zoppoli, Gabriele > (NIH/NCI) [G] > <zoppolig at mail.nih.gov> > wrote: > > Sorry, maybe it's easy but I haven't found anything > useful: > > > > how can I obtain a list C that contains all the > members in the list B that are not in list A? This are lists > of nanes, not numbers! > > > > Thank you > > > > > > Gabriele Zoppoli, MD > > Ph.D. Fellow, Experimental and Clinical Oncology and > Hematology, University of Genova, Genova, Italy > > Guest Researcher, LMP, NCI, NIH, Bethesda MD > > > > Work: 301-451-8575 > > Mobile: 301-204-5642 > > Email: zoppolig at mail.nih.gov > > ______________________________________________ > > 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. > > > > ______________________________________________ > 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. >