Say I have two character vectors
vec <- c('A', 'B', 'C', 'D', 'E')
pat <- c('D', 'B', 'A')
how do I get the indexes of the occurrences in vec
of the values in pat
in the order they appear in pat
?
I can try
which(vec %in% pat)
but this gives me them in the incorrect order: 1 2 4
. I want them as 4 2 1
.
match(pat, vec)
help("%in%")
returns the man formatch
.%in%
is also documented on that help page.