Re: [R] Testing whether a number belong to a set

2011-02-02 Thread Phil Spector
Dhiman - You don't say what you want the result to be if the value is in both S1 and S2, but here's an example that may give you some ideas: S1 = c('one','two','three') S2 = c('four','five','six') test = c('one','two','three','four','five','six','seven') test %in% S1 + 2 * test %in% S2 [1]

Re: [R] Testing whether a number belong to a set

2011-02-02 Thread Dennis Murphy
Hi: Try this: S1 <- sample(10001:98999, 1000) S2 <- sample(10001:98999, 1000) > intersect(S1, S2) # lists have some overlap [1] 72484 82292 93508 50438 29603 28965 68063 79598 16497 43016 22119 # test list x <- sample(10001:98999, 1000) # tests first if x is in S1; if not, test whether it's i

Re: [R] Testing whether a number belong to a set

2011-02-02 Thread Eik Vettorazzi
Hi, i think %in% will do exactly what you want eg. 5 %in% 1:10 Am 02.02.2011 21:49, schrieb DHIMAN BHADRA: > Hello everyone, > > I am stuck with an apparently simple issue : > > i) I have two sets S1 and S2, each containing a large number of integers, > say zip codes. > ii) Now, I just want to

Re: [R] Testing whether a number belong to a set

2011-02-02 Thread Seeliger . Curt
> So I was thinking of embedding it into a if else loop but I am stuck on how > to define the "belongs to" in R syntax. Any hint will be much appreciated. ?ifelse# handles vectors, while if() handles single values ?'%in%'# also see match() and which() Enjoy the day, cur -- Curt Seelig

[R] Testing whether a number belong to a set

2011-02-02 Thread DHIMAN BHADRA
Hello everyone, I am stuck with an apparently simple issue : i) I have two sets S1 and S2, each containing a large number of integers, say zip codes. ii) Now, I just want to test whether a particular zip code belong to S1 or S2 or neither of them. iii) If it belongs to S1, the area/region gets a