I have been trying with merge and joint options from dplyr
package, but I can't get the type of merging I'm looking for.
An example, considering the data.frame
:
df1 <- data.frame(Country=c(rep("AFG",3),rep("AUS",3)), Category=(rep(c("a","b","c"),2)), value=c(1:6), othr=c(10:15))
and another data.frame
:
df2 <- data.frame(Country=c(rep("AFG",2)), Category=c("a","b"), value=c(7,8))
The desirable output would be something like this:
Country Category value othr
1 AFG a 7 10
2 AFG b 8 11
3 AFG c 3 12
4 AUS a 4 13
5 AUS b 5 14
6 AUS c 6 15
i.e., df1$value
is replaced in AFG-a and AFG-b by df2$value
. I want to include this operation in a loop making many changes based on "Country" and "Category" columns (in my real data there are more than two columns to be matched)
Thanks a lot!