How to assemble a data.frame with equal elements from two other data.frames



I have two data.frames, each with 1 column. One data.frame has 3701 lines, while the other has more than 50,000 lines. What I want is the following: to assemble a data.frame that contains only the elements of the data.frame with 3701 lines that are present in the 50 thousand lines. I've tried a lot, but I couldn't get out of the corner.


I'm not sure that's what you want, but I thought of the following scenario:

df1<-data.frame(a=1:20) # Data frame com apenas 20 elementos
df2<-data.frame(b=11:50) # Data frame com 40 elementos
df3<-df2[which(is.element(df2$b,df1$a)),] # Seleciona os elementos do 
                                          # df2 que estão contidos no df1  
Scroll to Top