I have two vectors with the same elements but in different order, how can I find the new position of the elements ? which()
should do the trick but I'm unable to figure out how to do that, any idea ?
For example :
v1 <- c("paris", "new york", "london", "sidney")
v2 <- c("sidney", "new york", "paris", "london")
> which(v1 %in% v2)
[1] 1 2 3 4
> which(v1 == v2)
integer(0)
What I'm trying to do is something like :
> find_new_position(v1, v2)
[1] 3 2 4 1