Let's say I have two starting data frames:
df1 <- data.frame(code1 = c("a", "b","z"), code2 = c("2", "3", "4"))
df2 <- data.frame(code1 = c("c", "o", "p"), code2 = c("2", "4", "5"),
column3 = "a", column4 = "b", column5 = "c")
I want to match the two data frames by the column 'code2' and where that's a match, replace the value of code1 in df1 to the value of code1 in df2 so that the final data frame looks like this:
df3<- data.frame(code1 = c("c", "b", "o"), code2 = c("2", "3", "4"))