I have 2 data frames with different number of columns each. Some of the columns are common between the 2 data frames. How can i rbind only the common columns of the two data frames to a new data frame?
i tried with library(plyr);rbind.fill(A,B) however it sets NA values in the columns that do not match, and this does not help me.
Thanks a lot
EC
Use
intersectto retrieve the common columns.As pointed out in the comments, you can replace the last line with
for a small performance and typing improvement.
also works but I think that it’s a tiny bit less clear.
You can also use dplyr equivalents for the last step.