Last active
August 29, 2015 14:06
-
-
Save halfak/7d72f05518162b5e63f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first = function(vector, condition, start=1){ | |
for(i in start:length(vector)){ | |
if(condition(vector[i])){ | |
return(i) | |
} | |
} | |
return(length(vector)) | |
} | |
vector = c(1,2,34,3,23,2,34,5,67,78,8,8,5,4,3,23,2,4,5,6,34,23,4) | |
start = 1 | |
while(start <= length(vector)){ | |
end_of_chunk = first(vector, function(v){v>10}, start) | |
if(end_of_chunk > start){ | |
print(vector[start:(end_of_chunk-1)]) | |
} | |
start = end_of_chunk + 1 | |
} | |
[1] 1 2 | |
[1] 3 | |
[1] 2 | |
[1] 5 | |
[1] 8 8 5 4 3 | |
[1] 2 4 5 6 |
Author
halfak
commented
Sep 16, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment