Skip to content

matrix evaluation using if function

3 messages · Ivan, David Winsemius, Berend Hasselman

#
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.
#
David Winsemius wrote:
Wouldn't this do it too (dsince the diagonal is set to false by lower.tri)?:

rownames(which(n == t(n) & lower.tri(n),  arr.ind=TRUE))

Berend



--
View this message in context: http://r.789695.n4.nabble.com/matrix-evaluation-using-if-function-tp3483188p3483785.html
Sent from the R help mailing list archive at Nabble.com.