Q:

Fast way to figure out if a number is inside a vector in R

I was hoping to figure out a fast way to find out if a number is contained within a vector for the purpose of passing it to an if statement.  So far, the best I have come up with is the following:
a = 5
b = 1:10

if(length(which(a==5)) > 0){

#Do something...

}

I'm sure there is a faster way of doing this.

A:

Use %in%:
if (a %in% b) ...

This may not necessarily be faster than what you've got (since it's just syntactic sugar for a match call) but it's certainly more compact and transparent.

