Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6968579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:28:10+00:00 2026-05-27T16:28:10+00:00

I have 2 data frames with different number of columns each. Some of the

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:28:11+00:00Added an answer on May 27, 2026 at 4:28 pm

    Use intersect to retrieve the common columns.

    dfr1 <- data.frame(x = 1:5, y = runif(5), z = rnorm(5))
    dfr2 <- data.frame(w = letters[1:5], x = 6:10, y = runif(5))
    common_cols <- intersect(colnames(dfr1), colnames(dfr2))
    rbind(
      subset(dfr1, select = common_cols), 
      subset(dfr2, select = common_cols)
    )
    

    As pointed out in the comments, you can replace the last line with

    rbind(
      dfr1[, common_cols], 
      dfr2[, common_cols]
    )
    

    for a small performance and typing improvement.

    rbind(
      dfr1[common_cols], 
      dfr2[common_cols]
    )
    

    also works but I think that it’s a tiny bit less clear.


    You can also use dplyr equivalents for the last step.

    library(dplyr)
    bind_rows(
      dfr1 %>% select({common_cols}), 
      dfr2 %>% select({common_cols})
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two data frames with two columns each. The first column is timestamps
I have two data frames: A and B of the same number of columns
I have a list L of data frames with two columns each...a key, and
I am using R and I have two data frames: carrots and cucumbers. Each
Let's say I have two data frames. Each has a DAY, a MONTH, and
I'm trying to do some data manipulation in R. I have 2 data frames,
I'm having some trouble indexing data.frames in R. I'm an R beginner. I have
I have a list of different data types (factors, data.frames, and vectors, all the
I have a data frame that looks like this, with two key columns and
I have three different data frames like so: V1.x<-c(1,2,3,4,5) V2.x<-c(2,2,7,3,1) V3.x<-c(2,4,3,2,9) D1<-data.frame(ID=c(A,B,C,D,E),V1.x=V1.x,V2.x=V2.x,V3.x=V3.x) V1.y<-c(2,3,3,3,5) V2.y<-c(1,2,3,3,5)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.