[R] Logical matrices

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed Nov 5 18:38:18 CET 2003


Aurora Torrente wrote:

> 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,]


"||" doesn't work vectorized, but "|" does, therefore try:

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

and please read
  ?"|"

Uwe Ligges



>  > 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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list