Skip to content

removeing only rows/columns with "na" value from square ( symmetrical ) matrix.

1 message · Rui Barradas

#
Hello,

Try

while(TRUE){
     ix <- apply(M, 2, function(x) sum(is.na(x)))
     if(all(ix == 0)) break
     ix <- max(which(ix == max(ix)))
     M <- M[-ix , -ix]
}
M

Note that in the original there's really no difference between columns 9 
and 10.
If in the above code you use 'min', column 9 is removed and it's still a 
minimum of removals.
(Like in any case of a tie.)

Hope this helps,

Rui Barradas

Em 21-05-2012 11:00, Nevil Amos <nevil.amos at monash.edu> escreveu: