#this should be what you want
x_y <- merge(x,y,by=c("year","code"))
#use the following code when some rows of x have no matching rows in y by "year" and "code"
#it will still append the non-matching rows
x_y <- merge(x,y,by=c("year","code"),all.x = TRUE)