[R] Testing whether a number belong to a set

Eik Vettorazzi E.Vettorazzi at uke.uni-hamburg.de
Wed Feb 2 22:05:05 CET 2011


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 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 particular label, say 1; if
> it belongs to S2, it gets a label 2 and if it doesnot belong to either S1 or
> S2, it gets a label 0.
> iv) I have to do this for a large number of zip codes as well.
> 
> 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.
> Best regards,
> Dhiman Bhadra
> 
> WPI, Worcester, MA 01609
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790



More information about the R-help mailing list