I am attempting to replace an entire column in a data frame while retaining the order of the original values. I have 2 data frames where in the first dataframe there is a column that is digit codes (these repeat and are randomly placed). I have a separate data frame that only has the codes in numerical order and another column with what i want the codes to be replaced with in the corresponding row. My goal is to used the second dataframe to replace all the codes int he first dataframe with the second column in the second data frame.
for example
df1 <- c(A, 1,
C, 14,
Z, 1,
F, 5)
df2 <- c(1, "apple",
5, "banana",
14, "pear")
newdf <- c(A, "apple",
C, "pear",
Z, "apple",
F, "banana")
an obvious problem i am running into when using a for loop is that df2 is not the same length or in the same order as df1. also manually replacing the code is not possible as there is well over 400,000 rows with over 500 classes of the code.