[R] Remove vector elements from another vector

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Sep 15 16:31:03 CEST 2005


"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




More information about the R-help mailing list