Re: [R] an operator for "contains"

From: Sarah Goslee <sarah.goslee_at_gmail.com>
Date: Sat 18 Jun 2005 - 06:45:18 EST

On 6/17/05, Mike R <mike.rstat@gmail.com> 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
Received on Sat Jun 18 07:50:23 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:50 EST