I've got one table that is a set of all of my columns, their possible corresponding values, and the description for each one of those values. For example, the table looks like this:
ID Column Value Description
1 Age A Age_20-30
2 Age B Age_30-50
3 Age C Age_50-75
4 Geo A Big_City
5 Geo B Suburbs
6 Geo C Rural_Town
And so on.. Next, I have my main data frame that is populated with the column values. What I'd like to do is switch all values in each column with their corresponding description.
Old:
ID Age Geo
1 A B
2 A A
3 C A
4 B C
5 C C
New:
ID Age Geo
1 Age_20-30 Suburbs
2 Age_20-30 Big_City
3 Age_50-75 Big_City
4 Age_30-50 Rural_Town
5 Age_50-75 Rural_Town
Now I know how I can do this for one column using the following (where lookup_df is a table for only one of my columns):
old <- lookup_df$Value
new <- lookup_df$Description
df$Age <- new[match(df$Age, old, nomatch = 0)]
But I am struggling to do this for all columns. My full set of data has >100 columns so doing this manually for each column isn't really an option (at least in terms of efficiency). Any help or pointers in the right direction would be a huge help.