I have two character vectors:
v1 <- c("Red 1", "Red 2", "Red 3", "Blue thing", "Blue car", "Yellow anything")
v2 <- c("Yellow", "Red", "Blue")
I would like to get a vector, the length of v1, containing the index in v2 of the element that it starts with.
# Desired result
result <- c(2, 2, 2, 3, 3, 1)
I have tried looking at some combination of which() and startsWith() but have not been able to vectorise the operation over both vectors.