I have a R data frame df1 that looks like below:
Product new_ID
Prod1 129000007
Prod2 7432309490
Prod3 1708289014
Prod4 4741602975
Prod5 906485301012
And another one, df2, which looks like:
Brand old_ID
Brand1 13554998333
Brand2 17432309490
Brand3 14300012960
Brand4 14741602975
Brand5 2710420383988
To give some context, the data comes from two different databases where product codes (columns new_ID and old_ID respectively) are represented slightly differently. For example, Prod 2 and Brand 2 are the same with one extra digit in the old_ID column value compared to the value in new_ID. Same for Prod 4 and Brand 4. Note that all the codes in new_ID are not in old_ID.
Edit: Also note that the difference between the new_ID and old_ID value is not always that of the leading digit. Sometimes the first and last digit of an old_ID value is dropped to get new_ID value.
So I want to find all the rows in df2 which contain the products in df1 using the fields old_ID and new_ID. I could think of matching the new_ID value in old_ID using grepl. But I think that can be done only one at a time.
Is there a better way to find a match of a vector of new_ID values in the old_ID column?