Dear all, I would like to take out the values from one vector that are equal to the values in another vector. Example: a <- c(1,2,3,4,5,6,7,8,9) b <- c(3,10,20,5,6) b_noRepeats = c(10,20) So I would like to have the vector b without the same values as vector a. Kind regards, João Fadista [[alternative HTML version deleted]]
On 6/28/07, João Fadista <Joao.Fadista@agrsci.dk> wrote:> > I would like to take out the values from one vector that are equal to the > values in another vector. > > Example: > a <- c(1,2,3,4,5,6,7,8,9) > b <- c(3,10,20,5,6) > b_noRepeats = c(10,20) > >b[!(b %in% intersect(a,b))] See ?intersect -- Christophe Pallier (http://www.pallier.org) [[alternative HTML version deleted]]
setdiff(b, a) 2007/6/28, Jo?o Fadista <Joao.Fadista a agrsci.dk>:> Dear all, > > I would like to take out the values from one vector that are equal to the values in another vector. > > Example: > a <- c(1,2,3,4,5,6,7,8,9) > b <- c(3,10,20,5,6) > b_noRepeats = c(10,20) > > So I would like to have the vector b without the same values as vector a. > > > Kind regards, > Jo?o Fadista > > > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help a stat.math.ethz.ch 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. > >-- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy
look at setdiff(), e.g., setdiff(b, a) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Jo?o Fadista" <Joao.Fadista at agrsci.dk> To: <r-help at stat.math.ethz.ch> Sent: Thursday, June 28, 2007 11:55 AM Subject: [R] compare 2 vectors Dear all, I would like to take out the values from one vector that are equal to the values in another vector. Example: a <- c(1,2,3,4,5,6,7,8,9) b <- c(3,10,20,5,6) b_noRepeats = c(10,20) So I would like to have the vector b without the same values as vector a. Kind regards, Jo?o Fadista [[alternative HTML version deleted]] --------------------------------------------------------------------------------> ______________________________________________ > R-help at stat.math.ethz.ch 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. >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Christophe Pallier wrote:> On 6/28/07, Jo?o Fadista <Joao.Fadista at agrsci.dk> wrote: > >> I would like to take out the values from one vector that are equal to the >> values in another vector. >> >> Example: >> a <- c(1,2,3,4,5,6,7,8,9) >> b <- c(3,10,20,5,6) >> b_noRepeats = c(10,20) >> >> >> > b[!(b %in% intersect(a,b))] > > See ?intersect >Hi, There is also a pretty useful operator %w/o% in the help page of %in%. see : > ?`%in%` > a <- c(1,2,3,4,5,6,7,8,9) > b <- c(3,10,20,5,6) > b %w/o% a [1] 10 20 Cheers, Romain -- Mango Solutions data analysis that delivers Tel: +44(0) 1249 467 467 Fax: +44(0) 1249 467 468 Mob: +44(0) 7813 526 123