[R] Find sequence in vector
ens
stavros at uw.edu
Fri Apr 6 19:25:15 CEST 2012
> a<-sample(1:6,100,replace=T)
> a
[1] 2 4 3 4 5 1 3 2 4 3 6 6 2 6 2 1 5 5 3 4 6 1 6 6 3 4 6 6 4 4 5 4 6 5 6
3 4 5 6 3 4 1 6 6 6 4 2 1 1 3 1 5 3 2 2 6 2 5
[59] 2 6 1 6 1 1 6 4 4 2 2 3 4 5 6 1 6 4 6 1 5 1 1 2 1 3 4 4 6 3 1 4 1 1 1
5 5 2 4 6 5 1
which(a<=3)
[1] 1 3 6 7 8 10 13 15 16 19 22 25 36 40 42 47 48 49
50 51 53 54 55 57 59 61 63 64 68
[30] 69 70 74 78 80 81 82 83 84 88 89 91 92 93 96 100
I want to know if the indices are sequential and if so, how many of them are
sequential in a row. Does anyone know the least clumsy way to do this. I am
a C++ user by default, so my instinct is probably too mess for R.
--
View this message in context: http://r.789695.n4.nabble.com/Find-sequence-in-vector-tp4537882p4537882.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list