Re: [R] isolate elements in vector that match one of many possible values

2008-09-09 Thread Adam D. I. Kramer
Check out ?match, ?"%in%" x <- c(1,2,3,4) y <- c(1,2,4) match(y,x) [1] 1 2 4 --Adam On Mon, 8 Sep 2008, Andrew Barr wrote: Hi all, I want to get the index numbers of all elements of a vector which match any of a long series of possible values. Say x <- c(1,2,3,4) and I want to know whi

Re: [R] isolate elements in vector that match one of many possible values

2008-09-08 Thread Rolf Turner
On 9/09/2008, at 1:55 PM, Andrew Barr wrote: Hi all, I want to get the index numbers of all elements of a vector which match any of a long series of possible values. Say x <- c(1,2,3,4) and I want to know which values are equal to 1, 2 or 4. I could do which(x == 1 | x==2 | x==4) [1] 1

[R] isolate elements in vector that match one of many possible values

2008-09-08 Thread Andrew Barr
Hi all, I want to get the index numbers of all elements of a vector which match any of a long series of possible values. Say x <- c(1,2,3,4) and I want to know which values are equal to 1, 2 or 4. I could do which(x == 1 | x==2 | x==4) [1] 1 2 4 This gets really ugly though, when the list of v