Re: [R] Handling "NA" in summation

2015-09-06 Thread Dan D
# it's not clear what your question is, but here's a stab in the dark at a solution! ind<- !is.na(dataframe$A) & !is.na(dataframe$B) dataframe$A[ind] + dataframe$B[ind] - Dan P.S. I'm sure there are ways to do this using one of R's functions for automatically removing NA's (na.rm = T), but unle

Re: [R] Handling "NA" in summation

2015-09-06 Thread ce
taframe$A ) -Original Message- From: "Sarah Goslee" [sarah.gos...@gmail.com] Date: 09/06/2015 07:00 PM CC: "r-help" Subject: Re: [R] Handling "NA" in summation I'm not quite sure how you get zero from that situation. Do you expect the answer to be 20? H

Re: [R] Handling "NA" in summation

2015-09-06 Thread Jeff Newmiller
>dataframe[ is.na(dataframe) ] <- 0 >dataframe[ is.nan(dataframe) ] <- 0 >dataframe[ is.infinite(dataframe) ] <- 0 > >-Original Message- >From: "Olu Ola via R-help" [r-help@r-project.org] >Date: 09/06/2015 06:24 PM >To: r-help@r-project.org >Su

Re: [R] Handling "NA" in summation

2015-09-06 Thread Sarah Goslee
> Date: 09/06/2015 06:24 PM > To: r-help@r-project.org > Subject: [R] Handling "NA" in summation > > 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 &

Re: [R] Handling "NA" in summation

2015-09-06 Thread Jeff Newmiller
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

Re: [R] Handling "NA" in summation

2015-09-06 Thread ce
I use something like : dataframe[ is.na(dataframe) ] <- 0 dataframe[ is.nan(dataframe) ] <- 0 dataframe[ is.infinite(dataframe) ] <- 0 -Original Message- From: "Olu Ola via R-help" [r-help@r-project.org] Date: 09/06/2015 06:24 PM To: r-help@r-project.org Subjec

[R] Handling "NA" in summation

2015-09-06 Thread Olu Ola via R-help
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 +