Suppose you have two Tables: Table A and Table B
Table A has the following columns:
ID Flag Color SpecialVar
M112 X Green 2344
M134 Blue 1923
M542 X Black 4452
M698 Purple 8857
Table B has the following columns:
ID Flag Color
M112 Green
M134 Blue
M784 Orange
M542 Black
For every ID in Table B, I want to add the "X" under the flag column, if the flag exists for that ID in Table A.
so the result would look like this, NEW TABLE B:
ID Flag Color
M112 X Green
M134 Yellow
M784 Orange
M542 X Black
Providing the data frames here:
TableA <- data.frame(ID = c("M112", "M134", "M542", "M698"), Flag = c("X", "", "X", ""), Color = c("Green", "Blue", "Black", "Purple"), SpecialVar = c(2344, 1923, 4452, 8857))
TableB <- data.frame(ID = c("M112", "M134", "M784", "M542"), Flag = c("", "", "", ""), Color = c("Green", "Blue", "Orange", "Black"))