[R] how to overlook the zero in the denominator

Chun-Ying Lee u9370004 at cc.kmu.edu.tw
Wed Jul 27 10:51:37 CEST 2005


Dear R users:

I have two set of data, as follow:
x<-c(0,0,0.28,0.55,1.2,2,1.95,1.85,
     1.6,0.86,0.78,0.6,0.21,0.18)
y<-c(0,0,0,0.53,1.34,1.79,2.07,1.88,
    1.52,0.92,0.71,0.55,0.32,0.19)
i<-1:length(x)

I want to sum each (x[i]-y[i])^2/x[i] together, 
like:
>Sum <-sum((x[i]-y[i])^2/x[i])
>Sum
[1] NaN

Because the denominator shoud not be zero.
So I want to overlook those when x[i]=0,
and just to sum those x[i] not equal to 0.
What should I do?
Any suggestion.
Thanks in advance !!




More information about the R-help mailing list