[R] matrix inf and zero's value replacement

Ragia Ibrahim ragia11 at hotmail.com
Wed May 13 08:04:08 CEST 2015


Dear Group,
I have the following matrix
m
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    0    2    1  Inf  Inf  Inf  Inf  Inf
[2,]    1    0    2  Inf  Inf  Inf  Inf  Inf
[3,]    2    1    0  Inf  Inf  Inf  Inf  Inf
[4,]    3    2    1    0  Inf  Inf  Inf  Inf
[5,]  Inf  Inf  Inf  Inf    0  Inf  Inf  Inf
[6,]  Inf  Inf  Inf  Inf    1    0  Inf  Inf
[7,]  Inf  Inf  Inf  Inf  Inf  Inf    0  Inf
[8,]    1    3    2  Inf  Inf  Inf    1    0

I want  all values grater than 0 = to 1 and zero other wise?
thanks in advance
so 
this used, 
m <-ifelse(  (m==0)||  is.infinite(m),0, 1   )

but it gave me  zero   result
replacing
|| with | ,make sense and return the matrix I was looking for.

what is the difference betwen boht || an | ? when to use each ?

thanks in advance
 		 	   		  
	[[alternative HTML version deleted]]



More information about the R-help mailing list