[R] Annoyance with %/%
ALBERTO VIEIRA FERREIRA MONTEIRO
albmont at centroin.com.br
Wed Mar 11 12:25:37 CET 2015
I've just found an annoyance with the behaviour of %/% which, BTW,
violated the sacred rule that for all a, and non-zero b:
a = b * (a %/% b) + a %% b
Namely, that Inf %/% n is not Inf, but NaN.
Why is this so? It's an annoyance, because in expressions like:
big.vector.1[a, b, c] <- big.vector.2[a, b, c] %/% n
we must treat Inf and -Inf as exceptions, when a simple division does
not have these exceptions
BTW, I treated this exception the way Grace Hopper would be proud of, namely,
"it's easier to ask forgiveness than it is to get permission", but at
the cost of memory:
big.vector.1 <- big.vector.2
big.vector.1[a, b, c] <- big.vector.2[a, b, c] %/% n
tst <- is.nan(big.vector.1)
if (any(tst)) big.vector.1[tst] <- big.vector.2
Alberto Monteiro
More information about the R-help
mailing list