I have two dataframes:
DF1 <- data.frame (col1 = c("a", "b", "c"),
col2 = c("4", "3", "6")
)
DF2 <- data.frame (col3 = c("x", "y", "z"),
col4 = c("18", "3", "5")
)
DF1
col2 col2
1 a 4
2 b 3
3 c 6
DF2
col3 col4
1 x 18
2 y 3
3 z 5
For each row I want to add DF2$col3 to DF1, if DF2$col4 has the same value as DF1$col2.
Same value <- copy x/y/z to new column in DF1
Different value <- write NA to new column in DF1
How can I do this?