You could do this
> V1 <- c("apple","honey","milk","bread","butter")
> V2 <- c("bread","milk")
> intersect(V1,V2)
[1] "milk" "bread"
> setdiff(V1,V2)
[1] "apple" "honey" "butter"
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Antje
> Sent: Wednesday, November 01, 2006 8:50 AM
> To: [email protected]
> Subject: [R] extract values from a vector
>
> Hello,
>
> I'm looking for a solution for the following problem:
> I have two vectors
>
> V1 <- c("apple","honey","milk","bread","butter")
> V2 <- c("bread","milk")
>
> now, I would like to know for each element in V1 if it's
> equal to one of the elements in V2 I could do:
> which(V1 == V2[1] | V1 == V2[2])
>
> but what if I don't know the length of V2 and it's content???
>
> Thank you in advance!
>
> Antje
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained, reproducible code.
>
______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.