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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:08:13+00:00 2026-06-08T03:08:13+00:00

I have four data.frames which all have the same columns, being the first the

  • 0

I have four data.frames which all have the same columns, being the first the same to all. In the variable columns there are some NAs.

First, I’d like to replace any value (which is not an NA) in each data.frame by the name of the data.frame.
Second, I’d like to merge the data.frames. In this case, for each NA, there will be some other data.frame which would have a value for it, so that I’d end with every cell filled with values (or names of the data.frames).

Here’s an example with two data.frames:

 >A
 name Q  W  E  R  T
 g1   NA NA 4  NA 0
 g2   3  2  NA 4  5
 g3   NA 1  NA 0  0
 g4   0  NA NA 1  9

 >B
 name Q  W  E  R  T
 g1   2  4  NA 1  NA
 g2   NA NA 5  NA NA
 g3   5  NA 0  NA NA
 g4   NA 6  4  NA NA

 >result
 name Q  W  E  R  T
 g1   B  B  A  B  A
 g2   A  A  B  A  A
 g3   B  A  B  A  A
 g4   A  B  B  A  A

I’ve tried some merge() and union() options differently. Also, I’ve tried to adapt answers to similar questions but I can’t seem to solve this.

Creating a function to replace NAs from one data.frame with values from another

Merging data frames with missing values in R

Thank you in advance!

  • 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-08T03:08:15+00:00Added an answer on June 8, 2026 at 3:08 am

    This may not generalize well for you, but for the data provided…

    A <- data.frame(Q=c(NA, 3, NA, 0),
                    W=c(NA, 2, 1, NA),
                    E=c(4, NA, NA, NA),
                    R=c(NA, 4, 0, 1),
                    T=c(0,5,0,9), row.names=paste0('g', 1:4), stringsAsFactors=FALSE)
    
    B <- data.frame(Q=c(2, NA, 5, NA),
                    W=c(4, NA, NA, 6),
                    E=c(NA, 5, 0, 4),
                    R=c(1, NA, NA, NA),
                    T=c(NA, NA, NA, NA), row.names=paste0('g', 1:4), stringsAsFactors=FALSE)
    

    The result will be “A” anywhere that is A is not NA. It will be “B” wherever B is not NA

    result <- A
    result[!is.na(A)] <- "A" 
    result[!is.na(B)] <- "B"
    
    #   Q W E R T
    #g1 B B A B A
    #g2 A A B A A
    #g3 B A B A A
    #g4 A B B A A
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four buttons, which have to push the same uiTableViewController, with different data
I have four tabs which the first one inserts data on the database, the
I have a data frame of daily data: df with four columns: Date, A,
The main concept goes like this. I have four listviews with its own data
I have a Database named CarsType.accdb there are four fields in the data base
I have customized uitableViewcell in which each cell show four data which are related
I have four folders which contain text files (tab delimited) of the same names,
I have a semi-melted data frame that looks like this: head(final_melt) Group Source variable
I have four db servers with the same db structure but different data. Currently
I have four level data structure defined like this: Dictionary<Type1, Dictionary<Type2, Dictionary<Type3, List<Type4>>>> The

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.