I would like to add a column that indicates whether a value appears in more than one group. Using the below example, value '4' appears in groups '1' and '2', so I would like to flag that value.
x = matrix(c(1,1,1,2,2,2,3,3,4,4,5,4), nrow = 6, ncol = 2, byrow = F)
x = data.frame(x)
x
# X1 X2
# 1 1 3
# 2 1 3
# 3 1 4
# 4 2 4
# 5 2 5
# 6 2 4
This would be the desired output:
# X1 X2 FLAG
# 1 1 3 False
# 2 1 3 False
# 3 1 4 True
# 4 2 4 True
# 5 2 5 False
# 6 2 4 True