How about this? a<-c(1,7,4,5,9,11) b<-c(7,4,9) a[!a %in% b]
b<-c(7,4,9, 100, 20, 34, 54) a[!a %in% b] see ?match, too HTH, Andy > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Alexander Sokol > Sent: Thursday, November 11, 2004 8:34 AM > To: [EMAIL PROTECTED] > Subject: [R] Logical "and" > > > Hello, > > I have the following very simple problem: > > Say I have two vectors, > > a<-c(1,7,4,5,9,11) > b<-c(7,4,9) > > I would like to create a vector containing the elements in a > which are not in > b. > > Obviously, this is possible by writing > > a[a!=b[1] & a!=b[2] & a!=b[3]] > > But I would like a solution which is applicable to the situation > where the > number of elements in b is unknown. > > I have looked in the R manuals, the FAQ and the mailing lists, > but have been > unable to find a solution. > > Thank you for your replies, > Alexander > > ______________________________________________ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > ______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html