You can use ifelse()

#Create data for example
x <- matrix(data=c(Inf, 2, 3, 4, Inf, 6, 7, 8, Inf), nrow=3)
#Turn Inf into zero.
x <- ifelse(x == Inf, 0, x)

Jeremy





On 14 November 2012 14:13, Nick Duncan <nickdunc@gmail.com> wrote:

> Dear All,
>
> I have a matrix in which the diagonal has the string "Inf" in it. In
> order to be able to do cluster analysis this needs to be replaced with
> a Zero.
> I can do this by putting it into Excel, replacing  and putting it back
> into R but it's tedious, and I am sure there is a simple way to do it
> in R.
> If you have the route to do this, it would be much appreciated.
> Best wishes
> Nick Duncan
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]


