r - compare top half matrix with bottom half -


if have following data:

mat1           <- matrix( c(0,2,3,1,0,1,1,1,1), nrow=3 ) rownames(mat1) <- letters[1:3] colnames(mat1) <- letters[1:3]  mat1 #  b c #a 0 1 1 #b 2 0 1 #c 3 1 1 

how data.frame know rowise matrix entries bigger column entries? e.g. want result mat1 sort of data.frame indicating:

a < b  < c  b > b = c c > c = b 

i have been messing around upper.tri etc using subtractions not helping.

to compare each element mat1[i,j] corresponding element on other side of diagonal mat1[j,i], can use transpose t.

r <- sign( mat1 - t(mat1) ) r #    b  c # 0 -1 -1 # b 1  0  0 # c 1  0  0  paste(    colnames(r)[col(r)],    ifelse(r>0, ">", ifelse(r<0, "<", "=")),    rownames(r)[row(r)]  ) # [1] "a = a" "a > b" "a > c" "b < a" "b = b" "b = c" "c < a" "c = b" "c = c" 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -