I want to merge two data frames with different lengths and two condtions. In particular, I want to add the score from df1 to df2 depending on the year and the Country (From). The logic is similar to the function VLOOKUP in Excel with two conditions. How can I achieve this with minimal code?
df1 <- read.table(text = "
Year Country Score
1 NE 0.8
1 UK 0.9
2 NE 0.7
2 UK 1
",header = T)
df2 <- read.table(text = "
Year From Vote To
1 NE 1 Ger
1 NE 2 I
1 UK 2 Ger
1 UK 3 I
2 NE 2 Ger
2 NE 2 I
2 UK 4 Ger
2 UK 2 I
",header = T)