If I have a character vector a,
a <- c("bob","jim","joe","fred")
and I have another character vector b, with the same elements but in a different order,
b <- c("joe", "jim", "fred", "bob")
is there a function that tells what element of a each element of b equates to? In other words, I would like a function that would return c(3,2,4,1) (because b is equivalent to c(a[3], a[2], a[4], a[1]). Thanks!
You’re looking for
match(b, a).