Re: [R] counting sets of consecutive integers in a vector

2015-01-04 Thread Mike Miller
ginal Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Mike Miller Sent: Monday, 5 January 2015 1:03 p.m. To: R-Help List Subject: [R] counting sets of consecutive integers in a vector I have a vector of sorted positive integer values (e.g., postive integers after ap

Re: [R] counting sets of consecutive integers in a vector

2015-01-04 Thread jim holtman
Here is a solution using data.table > require(data.table) > x <- data.table(v, diff = cumsum(c(1, diff(v)) != 1)) > x v diff 1: 10 2: 20 3: 51 4: 61 5: 71 6: 81 7: 252 8: 303 9: 313 10: 323 11: 333 > x[, list(value = v[1L], length = .

Re: [R] counting sets of consecutive integers in a vector

2015-01-04 Thread jim holtman
oject.org] On Behalf Of Mike > Miller > Sent: Monday, 5 January 2015 1:03 p.m. > To: R-Help List > Subject: [R] counting sets of consecutive integers in a vector > > I have a vector of sorted positive integer values (e.g., postive integers > after applying sort() and unique()). F

Re: [R] counting sets of consecutive integers in a vector

2015-01-04 Thread Peter Alspach
f Mike Miller Sent: Monday, 5 January 2015 1:03 p.m. To: R-Help List Subject: [R] counting sets of consecutive integers in a vector I have a vector of sorted positive integer values (e.g., postive integers after applying sort() and unique()). For example, this: c(1,2,5,6,7,8,25,30,31,32,33) I w

[R] counting sets of consecutive integers in a vector

2015-01-04 Thread Mike Miller
I have a vector of sorted positive integer values (e.g., postive integers after applying sort() and unique()). For example, this: c(1,2,5,6,7,8,25,30,31,32,33) I want to make a matrix from that vector that has two columns: (1) the first value in every run of consecutive integer values, and (2