Hi,
When you merge two Dataframes, the result is a new Dataframe that contains data from both Dataframes. The key argument in the merge() is by. The by argument specifies how rows should be matched during the merge. You can see the below example.
risk.survey <- data.frame(
"participant" = c(1, 2, 3, 4, 5),
"risk.score" = c(3, 4, 5, 3, 1))
happiness.survey <- data.frame(
"participant" = c(4, 2, 5, 1, 3),
"happiness.score" = c(20, 40, 50, 90, 53))
# Combine the risk and happiness surveys by matching participant.id
combined.survey <- merge(x = risk.survey,
y = happiness.survey,
by = "participant",
all = TRUE)