Skip to content
Prev 75621 / 398502 Next

Conditional Matrices

On 16-Aug-05 ISAIAH SHALWITZ wrote:
It seems the following is what you are looking for:

A<-matrix(c(1,0,1,0,1,1,1,1,1),nrow=3)
A
#      [,1] [,2] [,3]
# [1,]    1    0    1
# [2,]    0    1    1
# [3,]    1    1    1

B<-matrix(c(1,2,3,4,5,6,7,8,9),nrow=3)
B
#      [,1] [,2] [,3]
# [1,]    1    4    7
# [2,]    2    5    8
# [3,]    3    6    9

B[A==0]<-NA
B
#      [,1] [,2] [,3]
# [1,]    1   NA    7
# [2,]   NA    5    8
# [3,]    3    6    9

Best wishes,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 16-Aug-05                                       Time: 09:08:25
------------------------------ XFMail ------------------------------