I have two data frames (df1 and df2) and I want to subset df2 based on the first two columns contained in df1. For example,
df1 = data.frame(x=c(1,1,1,1,1),y=c(1,2,3,4,5),value=c(3,4,5,6,7))
df2 = data.frame(x=c(1,1,1,1,1,2), y=c(5,3,4,2,1,6), value=c(8,9,10,11,12,13))
As we can see, row 6 (2,6) in df2 is not included in df1, so I will just select row 1 to row 5 in df2.
Also, I want to rearrange df2 based on df1. The final result should be like this:
Thanks for any help.


df1 %>% select(x,y) %>% inner_join(df2, by=c("x","y"))