Last active
June 6, 2023 21:02
-
-
Save acvill/6f611989d8fc1f663b2cd91d94c95dfb to your computer and use it in GitHub Desktop.
extract 1-based indices from a circular sequence within a range of a given index
This file contains 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
getrange <- function(i, length, range){ | |
sort(c( | |
c(((i - 1) - c(1:range)) %% length + 1), | |
i, | |
c(((i - 1) + c(1:range)) %% length + 1) | |
)) | |
} | |
## example: get a vector of indices +/- 10 around i = 5 on the circular integer interval [1,100] | |
getrange(i = 5, length = 100, range = 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment