print(match(5, c(2,7,5,3))) # 5 is in 3rd place print(seq(from=1,to=3,by=.5) %in% 1:3)
[1] 3 [1] TRUE FALSE TRUE FALSE TRUE
The match function find the first occurrence of the first argument in the second argument:
match(x=3, table=2:6)
[1] 2
The nomatch argument
By default match returns NA if no match for x is found in table. You can change this by using the nomatch argument:
match(1, 4:8, nomatch=-1)
[1] -1
The %in% operator
According to the documentation the following two lines are equivalent:
match(x, table, nomatch = 0) > 0 x %in% table
Using %in% can be more readable and provides you with a list of TRUE/FALSE values.