Dear R users.
I'm trying to avoid using nested loops in the following code but I'm not sure how to proceed. Any help would be greatly appreciated.
With regards,Phil
X = matrix(rnorm(100), 10, 10)
## Version with nested loopsresult = 0
for(m in 1:nrow(X)){  for(n in 1:ncol(X)){        if(X[m,n] != 0){      result = result + (X[m,n] / (1 + abs(m - n)))    }      }}
## No loop-sum(ifelse(M > 0, M/??? , 0))

 		 	   		  
	[[alternative HTML version deleted]]

