[R] Handling "NA" in summation

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Mon Sep 7 00:58:04 CEST 2015


That is not how R works. 20+NA is NA, which is not the same as zero. This is not optional behaviour.

I notice that you put quotes around the NA.... if those really are there then you should be getting an error.

You need to assemble a reproducible example, such as is described at [1]. By doing so you will either see your mistake or have something we can help you debug. Be sure to give one or more examples of results you expect to obtain, since your email below does not indicate what your desired result is.

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On September 6, 2015 3:22:32 PM PDT, Olu Ola via R-help <r-help at r-project.org> wrote:
>Hello,
>I am currently working with a dataframe which has some missing values
>represented by "NA". whenever, I add two columns in which at least one
>of the pair of an observation is "NA", the sum returns zero. That is
>for the same observation, if 
>
>dataframe$A = 20
>dataframe$B = NA
>
>dataframe$A + dataframe$B  returns zero.
>
>I do not want to delete the observations with the NA's. How do I go
>about carrying out the necessary operations without deleting the
>observations with the NA's
>
>Thank you
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list