[R] comparing matrices

Esmail esmail.js at gmail.com
Sun Apr 26 19:02:51 CEST 2009


I'm trying to compare two matrices made up of bits.

doing a simple comparison of

         matA == matB

yields this sort of output.

       [,1] [,2]  [,3]  [,4]  [,5]  [,6]
[1,] FALSE TRUE FALSE  TRUE  TRUE FALSE
[2,]  TRUE TRUE  TRUE  TRUE  TRUE  TRUE
[3,] FALSE TRUE FALSE FALSE FALSE  TRUE
[4,] FALSE TRUE  TRUE FALSE FALSE FALSE
[5,]  TRUE TRUE  TRUE  TRUE FALSE FALSE
[6,]  TRUE TRUE  TRUE  TRUE FALSE FALSE

I really would like just one comprehensive value to say TRUE or FALSE.

This is the hack (rather ugly I think) I put together that works,
but there has to be a nicer way, no?

     res=pop[1:ROWS,] == keep[1:ROWS,]

     if ((ROWS*COL) == sum(res))
      {
        cat('they are equal\n')
      }else
        cat('they are NOT equal\n')

Thanks!

Esmail




More information about the R-help mailing list