Say I have df1 that contains names in column 1 and numerical values in the other columns, and I have df2 that contains the same set of names in column 2 and a unique corresponding identifier in column 1.
The order of the names in the dfs don't match so I need a way to replace df1 names with df2 identifiers.
I know I can do something similar with the dplyr rename function but my dataframes are HUGE so that's a lot to manually write out. I thought this could be done in base R with a simple for/if loop using logical arguments but I feel like there has to be an easier way? Any help, tips or tricks would be appreciated.
For example:
View(df1)
| Name | Value | etc. |
|---|---|---|
| Heart | 2 | ... |
| Brain | 5 | ... |
| Blood | 10 | ... |
| Lung | 3 | ... |
| ... | ... | ... |
View(df2)
| ID | Type |
|---|---|
| H | Heart |
| L | Lung |
| Br | Brain |
| Bl | Blood |
| ... | ... |
After code:
View(df1)
| Name | Value | etc. |
|---|---|---|
| H | 2 | ... |
| Br | 5 | ... |
| Bl | 10 | ... |
| L | 3 | ... |
| ... | ... | ... |