[R] Conditional Operation in Matrix
Romildo Martins
romildo.martins at gmail.com
Wed Nov 24 15:54:03 CET 2010
Hello,
I would like to perform the operation a - b, only for the non-zero values.
Thanks a lot!
RMB
> a
0 0 0 0 4 0 0 0
0 0 0 0 0 3 0 0
0 0 0 0 0 0 0 3
0 0 0 0 0 0 4 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
> b
0 4 4 4 4 4 4 4
0 0 4 4 4 4 4 4
0 0 0 4 4 4 4 4
0 0 0 0 4 4 4 4
0 0 0 0 0 5 5 5
0 0 0 0 0 0 5 5
0 0 0 0 0 0 0 5
0 0 0 0 0 0 0 0
> a-b (expected)
0 0 0 0 0 0 0 0
0 0 0 0 0 -1 0 0
0 0 0 0 0 0 0 -1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
More information about the R-help
mailing list