%in%
returns a logical vector, the same length as vector 1, that indicates whether each element of vector 1 occurs in vector 2.
In contrast, the match
function returns, for each element of vector 1, the position in vector 2 where the element first appears (or NA
if it doesn't exist in vector 2). Try the following:
df[match(v, df$code), 'value']