I have two data frames, \"data\" and \"scores\", and want to merge them on the \"id\" column:
data = data.frame(id = c(1,2,3,4,5),
state =
In base you can use match to Select only the first row when merging data frames with multiple matches.
#Return also those which found no match
(tt <- cbind(data, score=scores[match(data$id, scores$id),"score"]))
# id state score
#1 1 KS 66
#2 2 MN 86
#3 3 AL 76
#4 4 FL NA
#5 5 CA NA
#Return only those which found a match
tt[!is.na(tt$score),]
# id state score
#1 1 KS 66
#2 2 MN 86
#3 3 AL 76