R语言中如何找出在两个数据框中完全相同的行(How to find common rows between two dataframe in R?)
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 id33 5 id45 6 id54
data.frame2
1 id832 2 id300 3 id1000 4 id45 5 id984 6 id5456 7 id888
So I want my output be:
1 id300 2 id45 3 id5456
any suggestion please?
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.

浙公网安备 33010602011771号