I am looking to perform a "find/replace" of factors across a large data frame using characters from another data frame.
To explain with a simple example, I have the following data frame (df):
ID1 ID2 value
1 A A 0.01
2 A D 0.02
3 B D 0.03
4 B C 0.04
5 C F 0.05
6 C D 0.06
7 D A 0.07
8 D C 0.08
And would like to replace each letter with a name, derived from the following data frame (id):
ID NAME
1 A ADAM
2 B BOB
3 C CARL
4 D DAVID
5 E EDWARD
6 F FRED
To end up with (new.df):
ID1 ID2 value
1 ADAM ADAM 0.01
2 ADAM DAVID 0.02
3 BOB DAVID 0.03
4 BOB CARL 0.04
5 CARL FRED 0.05
6 CARL DAVID 0.06
7 DAVID ADAM 0.07
8 DAVID CARL 0.08
I know there are many simple options that would involve writing out all replacement options (i.e. A="ADAM"), but I need to replace 1000's of factors so this is not an option.
I'm not sure where to start! I tried out car::recode
using this recode website but it only replaces in a vector.