Last active
August 29, 2015 14:26
-
-
Save MattSandy/29294795e93b720c6ac6 to your computer and use it in GitHub Desktop.
Breaks a vector into defined segment lengths
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
#Define the interval to cycle through | |
interval <- 30 | |
#Replace sample_vector with your vector | |
sample_vector <- runif(100, 1, 10) | |
#Loop through each break in the sequence | |
for(i in seq(1,length(sample_vector),interval)) { | |
#Used to prevent the sequence from extending beyond the remainders | |
if(i+interval>=length(sample_vector)) { | |
#Vector access for this sequence is as follows: | |
print(sample_vector[i:length(sample_vector)]) | |
} else { | |
#Vector access for this sequence is as follows: | |
print(sample_vector[i:(i+(interval-1))]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment