Hello, I have two vectors of different lengths. Fx a <- 1:9; b <- c(4, 5). What is the best way to remove the elements in vector b from vector a so that the result would be a vector with elements c(1,2,3,6,7,8,9)? Best regards, Kalle _________________________________________________________________ Find masser af gode tilbud p?? MSN Shopping http://shopping.msn.dk/
Karsten Luder wrote:> Hello, > > I have two vectors of different lengths. Fx a <- 1:9; b <- c(4, 5). > What is the best way to remove the elements in vector b from vector a so > that the result would be a vector with elements c(1,2,3,6,7,8,9)?setdiff(a, b) Uwe Ligges> Best regards, > Kalle > > _________________________________________________________________ > Find masser af gode tilbud p?? MSN Shopping http://shopping.msn.dk/ > > ______________________________________________ > 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
"Karsten Luder" <kalleswedens at hotmail.com> writes:> Hello, > > I have two vectors of different lengths. Fx a <- 1:9; b <- c(4, 5). > What is the best way to remove the elements in vector b from vector a so > that the result would be a vector with elements c(1,2,3,6,7,8,9)?I think we had this on the list no more than a week ago... setdiff(a,b) -- O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Hi On 13 Sep 2005 at 14:35, Karsten Luder wrote:> Hello, > > I have two vectors of different lengths. Fx a <- 1:9; b <- c(4, 5). > What is the best way to remove the elements in vector b from vector a > so that the result would be a vector with elements c(1,2,3,6,7,8,9)?> which(!a%in%b)[1] 1 2 3 6 7 8 9> a[which(!a%in%b)][1] 1 2 3 6 7 8 9> a[(!a%in%b)][1] 1 2 3 6 7 8 9>HTH Petr> > Best regards, > Kalle > > _________________________________________________________________ Find > masser af gode tilbud p?? MSN Shopping http://shopping.msn.dk/ > > ______________________________________________ > 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.htmlPetr Pikal petr.pikal at precheza.cz
look at function ?setdiff(), e.g.,
setdiff(a, b)
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/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Karsten Luder" <kalleswedens at hotmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, September 13, 2005 2:35 PM
Subject: [SPAM?] [R] Remove vector elements from another vector
Hello,
I have two vectors of different lengths. Fx a <- 1:9; b <- c(4, 5).
What is the best way to remove the elements in vector b from vector a
so
that the result would be a vector with elements c(1,2,3,6,7,8,9)?
Best regards,
Kalle
_________________________________________________________________
Find masser af gode tilbud p?? MSN Shopping http://shopping.msn.dk/
______________________________________________
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
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm