Find consecutive sub-vectors of length k out of a numeric vector which satisfy a given condition
Posted
by
user3559153
on Stack Overflow
See other posts from Stack Overflow
or by user3559153
Published on 2014-08-23T16:14:57Z
Indexed on
2014/08/23
16:20 UTC
Read the original article
Hit count: 133
r
I have a numeric vector in R, say
v= c(2,3,5,6,7,6,3,2,3,4,5,7,8,9,6,1,1,2,5,6,7,11,2,3,4).
Now, I have to find all the consecutive sub-vector of size 4 out of it with the condition that each element of the sub-vector must be greater than 2 and all sub-vector must be disjoint in the sense that non of the two sub-vector can contain same index element. So my output will be:
(3,5,6,7),(3,4,5,7),(5,6,7,11).
[Explanation: c(2,3,5,6,7,6,3,2,3,4,5,7,8,9,6,1,3,2,5,6,7,11,2,3,4) ]
© Stack Overflow or respective owner