Skip to content
Prev 275670 / 398506 Next

question R regarding consecutive numbers

On Oct 27, 2011, at 9:21 AM, Duncan Murdoch wrote:

            
And to go even a bit further, the table function returns a matrix  
which can be addressed to yield the specific answer requested:

  with(runs, table(values, lengths))["1",2]
[1] 1  # m=number of exactly runs if length 2
 > sum( tbl["1", 2:ncol(tbl)] )
[1] 2  # number of runs of length two or more.