[R] Remove vector elements from another vector

Petr Pikal petr.pikal at precheza.cz
Thu Sep 15 16:31:43 CEST 2005


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.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list