[R] Compare matrices

Andrej Kastrin andrej.kastrin at gmail.com
Mon Jan 19 21:48:14 CET 2009


Dear all,

Suppose that I have a matrix A

    A <- matrix(c(3,3,3,3,3,3,3,3,3),3,3)

and a logical matrix B

    B <- matrix(c(T,T,T,F,T,T,F,T,F),3,3)

The result  matrix should be

    C <- matrix(c(3,3,3,NA,3,3,NA,3,NA),3,3)

Is there any simple tip or trick to perform this without looping?

Thanks in advance for any suggestion.

Best regards, Andrej




More information about the R-help mailing list