I have a question about R programming. If I have two tables like:
Table_1
Name Flag
AA 0
BB 1
CC 0
DD 1
EE 1
FF 1
GG 0
HH 1
and
Table_2
Name Value Flag
AA 20 0
BB 30 1
BB 50 1
CC 40 0
EE 30 1
EE 80 1
GG 20 0
HH 70 1
DD 50 1
FF 10 1
I need the output like Table_3 which is combination of Table_1 and Table_2 such as,
whenever there is Flag 1 in Table_2 (common field in both tables) the value should be added to Table_1.
The Name and Flag in both tables Table_1 and Table_2 will remain same, for ex. if AA has flag 0 in Table_1 then it will be the same in Table_2.
In result table Table_3 rows must be same as Table_1 and values must be added to respective Name from Table_2.
Question: How can I do it? Is it possible to apply For loop (tables have large number of rows) or simply manipulation of tables.
Table_3
Name Flag Value
AA 0 0
BB 1 80
CC 0 0
DD 1 50
EE 1 110
FF 1 10
GG 0 0
HH 1 70