I have two data frames
The first frame is my IDs, some 'old code' matches to one 'Master ID'. Some OLD code are not matched to a Master ID.
ID Dataframe
MASTER ID OLD CODE
MASTER1 1A
MASTER1 1B
MASTER2 2
MASTER3 3
4
Sales
OLD CODE Salesvalues
1A 10
1B 15
2 6
3 8
4 5
If I am doing a right join or an outer join, it returns more rows then my original sales table. How I can make a join on the first matching 'MASTER ID' match and keeping the same number of rows(no multiple duplicate rows). I would like if there is no match for the'old code' on 'master ID', that will returns NA.
Expected Merge dataframe
OLD CODE Salesvalues MASTER ID (Join column)
1A 10 MASTER1
1B 15 MASTER1
2 6 MASTER2
3 8 MASTER3
4 5 NA