Apologies if this is a duplicate question, I have a feeling it has been asked, but I will provide a good example to help with understanding this. First the demo dataframes:
Another way would be to use your map_df as a look-up table.
rownames(map_df) = map_df$name main_df$P1 = map_df[main_df$P1, "id"] main_df$P2 = map_df[main_df$P2, "id"]