Run loop to match values from two different datasets

A much better solution than a loop would be a dplyr "join", take a look at the documentation

https://dplyr.tidyverse.org/reference/join.html

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.