Skip to content
Prev 310823 / 398503 Next

Replacing string in matrix with zero

Hello,

I doubt your Inf is a string, R does have the numeric value Inf (and 
-Inf), just try 1/0.
As for the question,

x <- matrix(1:9, ncol = 3)
diag(x) <- 1/0
x
x[x == Inf] <- 0
x

Note that it could also be diag(x) <- 0

Hope this helps,

Rui Barradas
Em 14-11-2012 22:13, Nick Duncan escreveu: