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 7792029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:04:12+00:00 2026-06-01T22:04:12+00:00

I have three data frames, the first (with column headers, but no row numbering)

  • 0

I have three data frames, the first (with column headers, but no row numbering) looks like

ID    1   2   3
 A   12  NA  NA
 B   NA   7  NA
 C   NA  NA  22

The second may look like

ID    1   2   3
 A   NA   6  NA
 B   NA  NA  29
 C   43  NA  NA

Lastly, the third looks like

ID    1   2   3
 A   NA  NA  32
 B    5  NA  NA
 C   NA   2  NA  

The first column is an ID column and the same for all three data frames. The final three columns represent the same variables (1, 2, and 3). The record for observation A, variable 1 is only in one of the data sets. So is the record for observation A, variable 2, but it’s in a different data set.

How can I merge these data sets together to get something like

ID    1   2   3
 A   12   6  32
 B    5   7  29
 C   43   2  22

I apologize that I didn’t have a better way of describing this problem. If someone could share the terminology for it, that would be great.

  • 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-06-01T22:04:13+00:00Added an answer on June 1, 2026 at 10:04 pm

    Nice title! This is quite similar to R – Vector/ Array Addition

    You can turn your data into a multi-dimensional array then sum or take the mean across the “puzzle piece” dimension:

    df1 <- read.table(text="ID    1   2   3
    A   12  NA  NA
    B   NA   7  NA
    C   NA  NA  22", header = TRUE)
    
    df2 <- read.table(text="ID    1   2   3
    A   NA   6  NA
    B   NA  NA  29
    C   43  NA  NA", header = TRUE)
    
    df3 <- read.table(text="ID    1   2   3
    A   NA  NA  32
    B    5  NA  NA
    C   NA   2  NA", header = TRUE)
    
    # gather inputs and remove common ID column
    lists  <- list(df1, df2, df3)
    pieces <- lapply(lists, '[', , -1)
    
    # turn data into a multi-dimensional array
    a <- array(unlist(pieces), dim = c(nrow(df1),
                                       ncol(df1) - 1,
                                       length(pieces)))
    
    # compute sums across pieces
    rowSums(a, na.rm = TRUE, dims = 2)
    # [,1] [,2] [,3]
    # [1,]   12    6   32
    # [2,]    5    7   29
    # [3,]   43    2   22
    

    Then you’re only left with pasting the ID column back.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming in R, I have a data.frame with the first column representing the time
I have three equal-sized data frames that I want to merge in a particular
I have two data frames. The one consists of three variables, namely date, strike
I have two data frames like so: A B 1 6 2 7 5
I have a data table the.data, where the first column indicate a measurement instrument,
I have three select boxes :- select1 select2 select3 , i am fetching data
In the /data directory of solr, suppose, I have three folders named as index,
In my application, I have three collection objects which store data. The data which
Ok, here's the condensed form. I have three main tables to draw data from:
I have a three tier system, SQL Server backend, hand written data access layer,

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.