Re: [R] an operator for contains
Yes, %in% or is.element(). Reid Huntsinger -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mike R Sent: Friday, June 17, 2005 4:32 PM To: r-help@stat.math.ethz.ch Subject: [R] an operator for contains k = c(1:9) if( length( which(k==3) ) ){ print(contained) }else{ print(not contained) } is therre a simple way to test if a vector/list contains a particular value? for example an operator, along the lines of: == more generally, is the a documentaion page that lists/describes all such operators? lastly, if you didn't know the answer to my question, how would you have gone about searching for an answer? I tried RSiteSearch() using various terms, and I opened R-2.1.0/library/base/html/00Index.html and searched for various terms. TIA == platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] an operator for contains
Does '?%in%' or '?match' meet your needs? spencer graves Mike R wrote: k = c(1:9) if( length( which(k==3) ) ){ print(contained) }else{ print(not contained) } is therre a simple way to test if a vector/list contains a particular value? for example an operator, along the lines of: == more generally, is the a documentaion page that lists/describes all such operators? lastly, if you didn't know the answer to my question, how would you have gone about searching for an answer? I tried RSiteSearch() using various terms, and I opened R-2.1.0/library/base/html/00Index.html and searched for various terms. TIA == platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] an operator for contains
See match(). Also intersect(). The documentation for operators is, I think mostly at the top of the index page for the base package, the one you searched. The relevant one is %in%. I guess Value matching didn't ring the right bell. On 06/17/05 13:31, Mike R wrote: k = c(1:9) if( length( which(k==3) ) ){ print(contained) }else{ print(not contained) } is therre a simple way to test if a vector/list contains a particular value? for example an operator, along the lines of: == more generally, is the a documentaion page that lists/describes all such operators? lastly, if you didn't know the answer to my question, how would you have gone about searching for an answer? I tried RSiteSearch() using various terms, and I opened R-2.1.0/library/base/html/00Index.html and searched for various terms. TIA == platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] an operator for contains
%in% R k - 1:9 R 3 %in% k [1] TRUE R 33 %in% k [1] FALSE Arne On Friday 17 June 2005 22:31, Mike R wrote: k = c(1:9) if( length( which(k==3) ) ){ print(contained) }else{ print(not contained) } is therre a simple way to test if a vector/list contains a particular value? for example an operator, along the lines of: == more generally, is the a documentaion page that lists/describes all such operators? lastly, if you didn't know the answer to my question, how would you have gone about searching for an answer? I tried RSiteSearch() using various terms, and I opened R-2.1.0/library/base/html/00Index.html and searched for various terms. TIA == platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Arne Henningsen Department of Agricultural Economics University of Kiel Olshausenstr. 40 D-24098 Kiel (Germany) Tel: +49-431-880 4445 Fax: +49-431-880 1397 [EMAIL PROTECTED] http://www.uni-kiel.de/agrarpol/ahenningsen/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] an operator for contains
On 6/17/05, Mike R [EMAIL PROTECTED] wrote: k = c(1:9) if( length( which(k==3) ) ){ print(contained) }else{ print(not contained) } is therre a simple way to test if a vector/list contains a particular value? Yes, several. Here's one: k - 1:9 if(any(k == 3)) { cat(is an element\n) } else { cat(not an element\n) } I don't recommend that for floating point numbers, though. more generally, is the a documentaion page that lists/describes all such operators? help(==) would get you the help page for the actual binary operators. Since any() isn't an operator, that won't help. lastly, if you didn't know the answer to my question, how would you have gone about searching for an answer? There are a variety of ways to find answers in R, although if you aren't certain what your keyword should be, it may take a few tries. help(), help.search(), and apropos() may all be useful. Sarah -- Sarah Goslee http://www.stringpage.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] an operator for contains
On Fri, 17 Jun 2005, Mike R wrote: k = c(1:9) if( length( which(k==3) ) ){ print(contained) }else{ print(not contained) } is therre a simple way to test if a vector/list contains a particular value? value %in% vector more generally, is the a documentaion page that lists/describes all such operators? No. You can find binary operators fairly effectively by looking at the html help, because they have to have non-alphabetic names (either single characters or beginning and ending with %). However, there are functions such as setdiff() that you might think of as binary operators that you wouldn't find this way. -thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] an operator for contains
wow. thanks everyone for the multitude of suggestions ! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html