Re: [R] How to generate a vector of counts i.e. the number of rows that are contiguous

2008-03-11 Thread Gabor Grothendieck
See ?diff and ?which: > x <- c(18004, 18005, 18006, 18007, 18008, 18009, 18010, 18011, + 18012, 18013, 18014, 18017, 18060, 18061, 18062, 18063, + 18064, 18065, 18066) > diff(which(diff(c(-Inf, x, Inf)) != 1)) [1] 11 1 7 > On Tue, Mar 11, 2008 at 10:37 AM, Ng Stanley <[EMAIL PROTECTED]> wrote:

[R] How to generate a vector of counts i.e. the number of rows that are contiguous

2008-03-11 Thread Ng Stanley
Hi, I have a 3 columns data and need to generate a vector of counts. These counts are the number of rows that are contiguous. It looks easy for manual counting, but to turn it algorithmic really split my head. For example, 11 (i.e. 18004 to 180014), 1 (i.e., 18017), 7 (i.e., 18060 to 18064) 1800