I have a matrix which includes 4 and six digit numbers, which basically comprise 2 or 3 pairs of digits, describing overlapping shapes. So, for example,
data1<-cbind(474440,470000,440000,40000,404400,474000).
Each cell of the matrix has either a 47
, a 44
, a 40
, or some combination of the above, and the rest of the number is zeros. I have another data set which is similar, but only has two pairs of numbers, not three. So, for example,
data2<-cbind(5253,5200,5300,50000,5053).
Again, this combination contains 52
,53
,50
, or some combination thereof. I would like to be able to select a logical matrix for each one of the two digit numbers, so selecting 40
in data1
would yield (TRUE,FALSE,FALSE,TRUE,TRUE,TRUE)
, and selecting 50
in data2
would yield (FALSE, FALSE, FALSE, TRUE, TRUE)
. I have tried creating a list of the unique two digit numbers I'm looking for, and using grepl to select those that match the pattern, but because of the zeros that are in the matrix which represent empty values, grepl selects too many of the cells; for example, looking for 40
in data1
would yield (TRUE, FALSE, TRUE,TRUE, TRUE, TRUE)
.