How to find common rows between two dataframe in R?

前端 未结 5 766
Happy的楠姐
Happy的楠姐 2020-12-30 02:21

I would like to make a new data frame which only includes common rows of two separate data.frame. example:

data.frame 1

1 id300
2 id2345
3 id5456
4 i         


        
5条回答
  •  一生所求
    2020-12-30 02:48

    The appropriate dplyr function here is inner_join (returns all rows from df x that have a match in df y.)

    library(dplyr)
    inner_join(df1, df2)
    
          V1
    1  id300
    2 id5456
    3   id45
    

    Note: the rows are returned in the order in which they are in df1. If you did inner_join(df2, df1), id45 would come before id5456.

提交回复
热议问题