Skip to content

Gap in solution

2 messages · Samir Benzerfa, David Winsemius

#
On Oct 28, 2011, at 4:08 AM, Samir Benzerfa wrote:

            
That is correct. Fully tested solutions are provided when complete  
example code displaying the complexity of the problem is offered. If I  
had been posed a question that actually had a "gap" then the first  
thing I would have tried would be to construct a logical test for the  
condition under scrutiny and apply it to the indexing system.  Using  
you example below (which is deficint in not having more than one  
column with hits)

 > str(with(runs, table(values, lengths)))
  'table' int [1:7, 1:2] 3 1 1 2 2 1 2 1 0 0 ...
  - attr(*, "dimnames")=List of 2
   ..$ values : chr [1:7] "1" "2" "3" "4" ...
   ..$ lengths: chr [1:2] "1" "3"
 > xtbl <- with(runs, table(values, lengths))
 > attr(xtbl, "dimnames")$lengths
[1] "1" "3"
 > which( as.numeric( attr(xtbl, "dimnames")$lengths) >=2 )
[1] 2

You could have just used that value, but I think it would be useful to  
test it with an example that has another run length > 2 including one  
that is "disjpoint"

 > x=c(1,3,4,9,1,9,1,5,4,5,2,1,1,1,6, 1,1,1,1,1)
 > xtbl <- with(rle(x), table(values, lengths))
 > xtbl
       lengths
values 1 3 5
      1 3 1 1
      2 1 0 0
      3 1 0 0
      4 2 0 0
      5 2 0 0
      6 1 0 0
      9 2 0 0
 > which( as.numeric( attr(xtbl, "dimnames")$lengths) >=2 )
[1] 2 3

So this is a better tested solution:
 > xtbl["1", which( as.numeric( attr(xtbl, "dimnames")$lengths) >=2 )]
3 5
1 1