[R] how to overlook the zero in the denominator
ramasamy at cancer.org.uk
Wed Jul 27 11:19:00 CEST 2005
The simplest way would be to ignore them in the sum
sum( ( x - y )/x, na.rm=T )
and notice that I have utilised the vectorised operation. But if you
want to, you can explicitly remove them with
good <- which( x != 0 )
sum( ( x[good] - y[good] )/ x[good] )
On Wed, 2005-07-27 at 16:51 +0800, Chun-Ying Lee wrote:
> Dear R users:
> I have two set of data, as follow:
> I want to sum each (x[i]-y[i])^2/x[i] together,
> >Sum <-sum((x[i]-y[i])^2/x[i])
>  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 !!
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help