Skip to content
Prev 258416 / 398502 Next

matrix evaluation using if function

On Apr 29, 2011, at 4:27 AM, ivan wrote:

            
Can you explain why "A" would not be an equally good answer to satisfy  
your problem set up?

 > which(n == t(n) & col(n) != row(n) , arr.ind=TRUE)
   row col
B   2   1
A   1   2
 > rownames(which(n == t(n) & col(n) != row(n) , arr.ind=TRUE) )
[1] "B" "A"

# Which would seem to be the correct answer, but
# This adds an additional constraint and also insures no diagonal  
elements

 > rownames(which(n == t(n) & col(n) != row(n) & lower.tri(n),  
arr.ind=TRUE) )
[1] "B"
I would rather program a problem correctly that hash through errors in  
loop logic.