When I execute 0 / 0
in R, I would get a NaN
as an output. But is there any way I could print 0 / 0
as 1
? I know I could use some if
statements to achieve it. I would like to know if there is any other way to achieve this.
You could define your own division symbol especially for this. For example,
'|' <- function(a,b)ifelse(a==0 & b==0, 1, a/b)
> 0|0
[1] 1
> 3|4
[1] 0.75