Hi I am looking into figuring out how to match data frames together by column, then renaming it. If there is no name that matches, then I would want to drop that column instead.
For example, I would use this main dataset, call it DF1:
| Name | Reference | Good | Fair | Bad | Great | Poor |
|---|---|---|---|---|---|---|
| George | Hill | 34 | 21 | 33 | 21 | 32 |
| Frank | Stairs | 29 | 28 | 29 | 30 | 29 |
| Bertha | Trail | 25 | 25 | 24 | 21 | 26 |
Then another DF, call this DF2, that allows me to replace the names of the columns of DF1
| Name | Adjusted_Name |
|---|---|
| Good | good_run |
| Great | very_great_work |
| Bad | bad run |
| Fair | fair run decent |
Essentially, the words that would be substituted would not be any pattern of any sort, and I would try to match this first column in DF2 and match to DF1, and if there is a match in DF2$Name and DF(whatever column), then I would replace that name with the same row of DF2$Adjusted_Name. If there is no match, then the value in DF1 is dropped.
So the final goal would be to achieve:
| Name | Reference | good_run | fair run decent | Bad run | very_great_work |
|---|---|---|---|---|---|
| George | Hill | 34 | 21 | 33 | 21 |
| Frank | Stairs | 29 | 28 | 29 | 30 |
| Bertha | Trail | 25 | 25 | 24 | 21 |
In this case, "poor" was dropped because it didnt match the column name of DF1.
How should I go about this? How would I account if there thousands of columns? Does that change anything in how i Code? I am a bit new to R, and would appreciate any tips. Thank you!