Skip to content

Instantly share code, notes, and snippets.

@MattSandy
Created July 7, 2015 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattSandy/5ad2183c31727d2cd814 to your computer and use it in GitHub Desktop.
Save MattSandy/5ad2183c31727d2cd814 to your computer and use it in GitHub Desktop.
Match repeated values in a vector based on a specified interval
vector <- c(10,1,0,10,0,0,10,0,0,10)
match_interval(vector,3))
match_interval <- function (vector, interval) {
matches <- c()
for(i in 1:interval) {
if(sd(vector[seq(i,length(vector),interval)])==0) {
matches[length(matches)+1] <- vector[i]
}
}
return(matches)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment