# NOT RUN {
# left is panel data and i does not uniquely identify observations
left <- data.frame(
i = c(1, 1, 2, 2),
t = c(1, 2, 1, 2),
a = 1:4
)
# right is individual-level data uniquely identified by i
right <- data.frame(
i = c(1, 2),
b = 1:2
)
# I think that I can do a one-to-one merge on i
# Forgetting that left is identified by i and t together
# So, this produces an error
# }
# NOT RUN {
safe_join(left, right, expect = "1:1", join = left_join)
# }
# NOT RUN {
# If I realize I'm doing a many-to-one merge, that is correct,
# so safe_join will perform it for us
safe_join(left, right, expect = "m:1", join = left_join)
# }
Run the code above in your browser using DataLab