i have two data.frames that i want to merge and replace values of certain columns of df1
with values of df2. in this working example there are only 3 columns. but in the original data,
there are about 20 columns that should remain in the final data.frame.
NO <- c(2, 4, 7, 18, 25, 36, 48)
WORD <- c("apple", "peach", "plum", "orange", "grape", "berry", "pear")
CLASS <- c("p", "x", "x", "n", "x", "p", "n")
ColA <- c("hot", "warm", "sunny", "rainy", "windy", "cloudy", "snow")
df1 <- data.frame(NO, WORD, CLASS, ColA)
df1
# NO WORD CLASS ColA
# 1 2 apple p hot
# 2 4 peach x warm
# 3 7 plum x sunny
# 4 18 orange n rainy
# 5 25 grape x windy
# 6 36 berry p cloudy
# 7 48 pear n snow
NO <- c(4, 18, 36)
WORD <- c("patricia", "oliver", "bob")
CLASS <- c("p", "n", "x")
df2 <- data.frame(NO, WORD, CLASS)
df2
# NO WORD CLASS
# 1 4 patricia p
# 2 18 oliver n
# 3 36 bob x
i want to merge the two data.frames and replace the values of WORD and CLASS from df1
with the values of WORD and CLASS from df2
my data.frame should look like this:
# NO WORD CLASS ColA
# 1 2 apple p hot
# 2 4 patricia p warm
# 3 7 plum x sunny
# 4 18 oliver n rainy
# 5 25 grape x windy
# 6 36 bob x cloudy
# 7 48 pear n snow