Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

replace NAs in a column in R Programming

I haven’t. A clue what I’m doing but

I need to replace NAs in a column in one dataset with info from the column in another dataset

I’m trying to help someone out and that’s their problem they need to solve

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Has anyone got any idea what the solution might be

>Solution :

As you haven’t provided any of your data, here is a base solution which may or not work for you depending on your situation. Please put more effort into your question if you need something more complicated than this.

df1 <- data.frame(a = c(1, 2, 3, 5, NA, 9))
df2 <- data.frame(a = c(2, 4, 5, 7, 20, 2))
df1$a <- ifelse(is.na(df1$a), df2$a, df1$a)
df1
#>    a
#> 1  1
#> 2  2
#> 3  3
#> 4  5
#> 5 20
#> 6  9
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading