[R] Logical matrices

Aurora Torrente aurora at ebi.ac.uk
Wed Nov 5 18:23:09 CET 2003


Hello,
I've been trying to work with 0-1 matrices as if they were logical, but 
using the logical operators doesn't produce what I need, for using the 
matrix B:

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    1    0    0
[2,]    0    1    0    0    0
[3,]    0    0    1    0    1

gives me the following:

 > B[1,]<-B[1,] || B[3,]

 > B
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    1    1    1
[2,]    0    1    0    0    0
[3,]    0    0    1    0    1

instead of :

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    1    0    1
[2,]    0    1    0    0    0
[3,]    0    0    1    0    1

which is what I need.
I've tried to convert it into a logical matrix, but the result was a vector:

 > C<-as.logical(B)
 > C
 [1]  TRUE FALSE FALSE  TRUE  TRUE FALSE  TRUE FALSE  TRUE  TRUE FALSE 
FALSE  TRUE FALSE  TRUE

What could I do? Thanks for your help,

        Aurora




More information about the R-help mailing list