I have a data frame that has a column for zip code. I also have a data frame that has a list of zip codes and which Metropolitan Statistical Area they belong to. I'm trying to append the MSA based on zip code. The zip codes in either data frame are not guaranteed to be in the other, and each zip code in the master data may be seen more than once. The data frame starts with 779 rows and should end with 779 rows. I've tried the merge command below
sheet <- merge(sheet, msa, by = "Zip", all.x = TRUE, all.y=FALSE)
However, the resulting data frame 1881 rows.
I've also tried using plyr
test <- join(sheet, msa, by = "Zip")
This also yields a data frame with 1881 rows.
I think I could do with what I want with %in% and a for loop, but I was hoping there was a command that could do what I want.
Thanks in advance for the help.