In the following example
x <- data.frame(code = 7:9, food = c(\'banana\', \'apple\', \'popcorn\'))
y <- data.frame(food = c(\'banana\', \'apple\', \'po
plyr
makes this easy:
x <- data.frame(code = 7:9, food = c('banana', 'apple', 'popcorn'))
y <- data.frame(food = c('banana', 'apple', 'popcorn'),
isfruit = c('fruit', 'fruit', 'not fruit'))
library(plyr)
join(x,y)
#GOOD
#Joining by: food
# code food isfruit
#1 7 banana fruit
#2 8 apple fruit
#3 9 popcorn not fruit
#BAD
# merge(x,y)
# food code isfruit
#1 apple 8 fruit
#2 banana 7 fruit
#3 popcorn 9 not fruit