Skip to content
Back to formatted view

Raw Message

Message-ID: <fb7c7e870803140337x3a17a4cftf50f223fff27de8d@mail.gmail.com>
Date: 2008-03-14T10:37:45Z
From: Rainer M Krug
Subject: Selecting elements in vector

Hi

Consider the following code

> x <- rep(1:13, 13)

> y <- 1:3

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

I know that I could use

> sel <- x==y[1] | x==y[2] | x==y[3]
> x[sel]

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
-- 
Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)

Plant Conservation Unit Department of Botany
University of Cape Town
Rondebosch 7701
South Africa