[R] Dividing by NA?

arun smartpink111 at yahoo.com
Tue Feb 11 04:01:47 CET 2014



Hi,
dat <- read.table(text="A     B              
 1     0
 2     2
 3     1
 4     NA",sep="",header=TRUE)
  within(dat,{C<-A/B;C[!is.finite(C)]<-0})
#
 within(dat,{C<-A/B;C[!is.finite(C)]<-NA})
A.K.


Hi R users, 

Just wondering is it possible to divide two columns with some NA or Zero values?  E.g.: 

A     B               
1     0 
2     2 
3     1 
4     0 

I want something like this: 

A    B    C 
1    0    0 (or NA) 
2    2    1 
3    1    3 
4    0    0 (or NA) 

Even though it is not meaningful to divide zero but the data I 
got have these missing values in a time series... Ignoring them will not
 have a material effect on my analysis. 

Thanks! 




More information about the R-help mailing list