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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:03:36+00:00 2026-06-01T20:03:36+00:00

After merging a dataframe with another im left with random NA’s for the occasional

  • 0

After merging a dataframe with another im left with random NA’s for the occasional row. I’d like to set these NA’s to 0 so I can perform calculations with them.

Im trying to do this with:

    bothbeams.data = within(bothbeams.data, {
      bothbeams.data$x.x = ifelse(is.na(bothbeams.data$x.x) == TRUE, 0, bothbeams.data$x.x)
      bothbeams.data$x.y = ifelse(is.na(bothbeams.data$x.y) == TRUE, 0, bothbeams.data$x.y)
    })

Where $x.x is one column and $x.y is the other of course, but this doesn’t seem to work.

  • 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-01T20:03:37+00:00Added an answer on June 1, 2026 at 8:03 pm

    You can just use the output of is.na to replace directly with subsetting:

    bothbeams.data[is.na(bothbeams.data)] <- 0
    

    Or with a reproducible example:

    dfr <- data.frame(x=c(1:3,NA),y=c(NA,4:6))
    dfr[is.na(dfr)] <- 0
    dfr
      x y
    1 1 0
    2 2 4
    3 3 5
    4 0 6
    

    However, be careful using this method on a data frame containing factors that also have missing values:

    > d <- data.frame(x = c(NA,2,3),y = c("a",NA,"c"))
    > d[is.na(d)] <- 0
    Warning message:
    In `[<-.factor`(`*tmp*`, thisvar, value = 0) :
      invalid factor level, NA generated
    

    It “works”:

    > d
      x    y
    1 0    a
    2 2 <NA>
    3 3    c
    

    …but you likely will want to specifically alter only the numeric columns in this case, rather than the whole data frame. See, eg, the answer below using dplyr::mutate_if.

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

Sidebar

Related Questions

After merging 2 LINQ lists, how can I preserve the table objects and names?
After merging a branch back to the trunk what do most people do with
After highlighting text, I would like to obtain the paragraph in which the selected
I'm having issues after merging 2 LINQ lists. I get the following error: the
I tried to merge two heads in Mercurial. After merging, I didn't commit and
How can I insert to a string comma (,) after every 3 position starting
Being that the svn boook recommends deleting a branch after merging it into the
Do I need to explicitly close a branch after merging it into trunk? Or
After reading How and/or why is merging in Git better than in SVN? I
reference from: Merging Variable PHP I have problem with $_POST getting blank null after

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.