In the following example
x <- data.frame(code = 7:9, food = c(\'banana\', \'apple\', \'popcorn\')) y <- data.frame(food = c(\'banana\', \'apple\', \'po
You can wrap it in your custom function. For example :
merge.keep <- function(...,ord=union(names(x), names(y)))merge(...)[ord]
then for example:
merge.keep(x,y) code food isfruit 1 8 apple fruit 2 7 banana fruit 3 9 popcorn not fruit
EDIT I use @Eddi idea to set default values of ord.