How to prevent merge from reordering columns

后端 未结 4 1445
长情又很酷
长情又很酷 2020-12-31 08:26

In the following example

x <- data.frame(code = 7:9, food = c(\'banana\', \'apple\', \'popcorn\'))
y <- data.frame(food = c(\'banana\', \'apple\', \'po         


        
4条回答
  •  情歌与酒
    2020-12-31 08:40

    Here's a generic version of your base workaround:

    merge(x, y)[, union(names(x), names(y))]
    

提交回复
热议问题