[R] extract values from a vector

Antje niederlein-rstat at yahoo.de
Wed Nov 1 18:09:24 CET 2006


Bernd Weiss schrieb:
> Am 1 Nov 2006 um 14:49 hat Antje geschrieben:
>
> Date sent:      	Wed, 01 Nov 2006 14:49:43 +0100
> From:           	Antje <niederlein-rstat at yahoo.de>
> To:             	R-help at stat.math.ethz.ch
> 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???
>>
>>     
>
>   
>> V1%in%V2
>>     
> [1] FALSE FALSE  TRUE  TRUE FALSE
>
> Is this what you are looking for?
>
> HTH,
>
> Bernd
>
>   

Thank you very much, that's what I need (I'm sorry for asking so stupid 
questions....)

Antje



More information about the R-help mailing list