Skip to content

Selecting elements in vector

4 messages · Gábor Csárdi, Henrique Dallazuanna, Rainer M Krug

#
Hi

Consider the following code
I want to select all elements in x which are equal to 1, 2 or 3.

I know that I could use
to obtain the values, but in my analysis, the y-vector is thousands of
elements long.

Is there any way, that I can do that easily?

Thanks

Rainer
#
Use %in%:

x [ x %in% y ]

G.
On Fri, Mar 14, 2008 at 12:37:45PM +0200, Rainer M Krug wrote:

  
    
#
Try this:

x[x %in% y]
On 14/03/2008, Rainer M Krug <r.m.krug at gmail.com> wrote:

  
    
#
Thanks - that is exactly what I was looking for

Rainer
On Fri, Mar 14, 2008 at 1:10 PM, Henrique Dallazuanna <wwwhsd at gmail.com> wrote: