Distinguishing between infinity and negative infinity during value replacement in R
Why not just combine is.infinite
with a standard >
or <
comparison?
a <- c(-1,2,3,4,100/0,-100/0)
a[is.infinite(a) & a < 0] <- min(a[!is.infinite(a)])
a[is.infinite(a) & a > 0] <- max(a[!is.infinite(a)])
a
[1] -1 2 3 4 4 -1