I'm wondering if there might be a setting I'm overlooking to force R
to return NaN
instead of ±Inf
when dividing by zero.
I too often findmyself doing something like
results[is.infinite(results)] <- NaN
I'm hoping to skip the filtering/search process altogether.
Example:
### Example:
num <- c(1:5, NA)
denom <- -2:3
quotient <- num / denom
[1] -0.5 -2.0 Inf 4.0 2.5 NA
# desired results
[1] -0.5 -2.0 NaN 4.0 2.5 NA
Simple way of achieving the desired results is:
quotient[is.infinite(quotient)] <- NaN
What I am wondering is if that last step can be avoided while still getting the same desired results.