Is there an R function for finding the index of an element in a vector?
The function match works on vectors: x <- sample(1:10) x # [1] 4 5 9 3 8 1 6 10 7 2 match(c(4,8),x) # [1] 1 5 match only returns the first encounter of a match, as you requested. It returns the position in the second argument of the values in the first argument. For … Read more