Re: [R] an efficient pairwise matrix cell's comparison function

2008-03-02 Thread jim holtman
Does this do what you want? A - matrix(sample(0:2, 25, TRUE), ncol=5) B - matrix(1:25, ncol=5) C - ifelse(A == 0, 0, B) A [,1] [,2] [,3] [,4] [,5] [1,]11121 [2,]10110 [3,]00102 [4,]01200 [5,]121

Re: [R] an efficient pairwise matrix cell's comparison function

2008-03-02 Thread Prof Brian Ripley
C - B C[A==0] - 0 would be somewhat more efficient. On Sun, 2 Mar 2008, jim holtman wrote: Does this do what you want? A - matrix(sample(0:2, 25, TRUE), ncol=5) B - matrix(1:25, ncol=5) C - ifelse(A == 0, 0, B) A [,1] [,2] [,3] [,4] [,5] [1,]11121 [2,]10