Suppose I have a list y, and I want to return to position of the first instance of every element of another list x=c('a','b','c') (i.e. the position of the first a, the first b, etc).
which(y %in% x)
will simply return all instances rather than the first instance. Another approach is to loop over all elements xi in x and use
min(which(y == xi))
Is there a way to do this without using a for loop over the elements in x? I've found several queries on stackoverflow on how to find the first instance of a single element in a list, but not for multiple elements.