Skip to content
Prev 156338 / 398506 Next

modifying patterns in a matrix

On Sep 17, 2008, at 3:50 PM, Stacey Burrows wrote:

            
I had some success in identifying the non-singletons using filter(x,  
c(1,1,1) and applying a test for that value being greater than 1. You  
would need to disambiguate  what should be happening at the end of the  
series since filter() would be NA there. Adding 0 to a logical vector  
returns 0's and 1's

 > t(apply(temp,1, function(x) filter(x, c(1,1,1)) ) )
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]   NA    1    1    1    2    3    2   NA
[2,]   NA    0    1    1    1    0    0   NA

  t(apply(temp,1, function(x) (filter(x, c(1,1,1)) >1)+0 ) )
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]   NA    0    0    0    1    1    1   NA
[2,]   NA    0    0    0    0    0    0   NA