Skip to content
Prev 268621 / 398502 Next

Selecting section of matrix

On Aug 15, 2011, at 6:09 AM, mdvaan wrote:

            
> tst <- h$`1999`
 > tst[tst[,"8025"]>0, tst["8025",]>0]
       B
B      8025 8026 8027
   8025    1    1    1
   8026    1    1    1
   8027    1    1    1
> tst[tst[,"8028"]>0, tst["8028",]>0]
       B
B      8028 8029
   8028    1    1
   8029    1    1

And to do it programmatically:

sapply( colnames(tst), function(var) tst[tst[,var]>0, tst[var,]>0])