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
The appropriate dplyr function here is inner_join (returns all rows from df x that have a match in df y.)
dplyr
inner_join
x
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.
df1
inner_join(df2, df1)
id45
id5456