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

The Archive Base Latest Questions

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

i have the following conundrum. I have a dataframe x that looks like: v2

  • 0

i have the following conundrum. I have a dataframe x that looks like:

     v2      v3    
10   4.0      3.0
11   5.0      3.0
12   6.0      9.0
13   5.0      6.0    # where 10-14 are rownames
14   3.0      6.0

and then the datafame y:

     value        
11   99            
13   88      #where 11,13,14 are row names
14   33

I would like to add value to x matching the rownames and filling the gaps with zeros.i.e.:

      v2      v3    value
10   4.0      3.0     0
11   5.0      3.0     99
12   6.0      9.0      0
13   5.0      6.0     88
14   3.0      6.0     33

Although if I have to fill with NAs maybe I can do this and then change NAs to zeros within the new y vector afterwards.

I have been trying variations of rbind.fill from plyr using newDF<-do.call(rbind.fill)but nothing i am achieving is working out the way i hope.

EDIT
i GOT IT TO GIVE NAS USING
merge(x,y,all=TRUE,by='row.names')

  • 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-01T16:04:08+00:00Added an answer on June 1, 2026 at 4:04 pm

    I would do it like that:

    y$row <- rownames(y)    # add a 'helper' column for the merge function.
    x$row <- rownames(x)
    n <-merge(x,y, by='row', all=T)
    n <- n[,-1]    # remove the 'helper' column
    

    and then replace the NAs by 0:

    n[is.na(n$value),]$value = 0
    

    But this fails, or will procude wrong results, if you have NAs in your y/x dataframe.

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

Sidebar

Related Questions

I have following script that executes all the .reg files in the current directory.
I have following code that creates Linq query. I've never used Linq until today
I have following table it shows like this: ABC A B C 123 Hello
I have following WPF ListView: <ListView Grid.Column=2 Grid.Row=1 Margin=0,53,12,6 Name=lvwProperties ItemsSource={Binding Path=SelectedPropertyItems, Mode=TwoWay} Grid.ColumnSpan=2>
I have following Html file with javascript. This gives me error that testCircle is
I have the following conundrum. In C#, I want to store a rational and
Here's my conundrum: I have a page that uses Google Maps V3 and jQuery.
I have following method that I select all the ids from table and append
Have following validation for year value from text input: if (!year.match(new RegExp('\\d{4}'))){ ... }
I have following XsL which opens the link in the same window. I would

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.