match two data.frames based on multiple columns

后端 未结 3 1693
被撕碎了的回忆
被撕碎了的回忆 2021-01-11 17:19

My head stands still at the moment. I would like to match/extract data from a larger data.frame (df) based on the columns in a smaller data.frame (mdf). What I\'m getting st

3条回答
  •  情书的邮戳
    2021-01-11 17:53

    How about merge(df, mdf, all.x = FALSE, all.y = TRUE)?

    Edit: If you have different column names you can specify which ones to merge on, e.g.:

    names(mdf) <- c("car_3", "car_4")
    merge(df, mdf, by.x = c("car_1", "car_2"), by.y = c("car_3", "car_4"), 
          all.x = FALSE, all.y = TRUE)
    

提交回复
热议问题