Given two vectors vecA and vecB, I would like to find the smallest n such that
all(vecB %in% vecA[1:n])
is TRUE.
This is in a tight inner loop, so speed would be good. Obviously I could do
n <- NA_integer_
for (i in seq_along(vecA)) {
if (all(vecB %in% vecA[1:i])) {
n <- i
break
}
}
but is there a faster/more elegant way?
One thing you can use: vecB is always going to be a sequence of the form 1:M.
Here's an example where n should equal 5:
vecB <- 1:3
vecA <- c(1, 2, 2, 1, 3, 2)