Skip to content

Instantly share code, notes, and snippets.

@InzamamRahaman
Created July 28, 2014 16:59
Show Gist options
  • Save InzamamRahaman/9b13a9c99bf521c59dbd to your computer and use it in GitHub Desktop.
Save InzamamRahaman/9b13a9c99bf521c59dbd to your computer and use it in GitHub Desktop.
# Determines if the vector does not having missing data over the range specified
contains_values <- function(start, end, coll) {
temp <- coll[start:end]
return(length(temp[!is.na(temp)]) == (end - start + 1))
}
# Determines if the data entry at this index is viable for consideration
is_good_index <- function(k, idx, coll) {
return(contains_values(idx - k, idx, coll))
}
# Finds all of the good indicies in the vector
find_good_indicies <- function(k, coll) {
idxs <- k : (length(coll))
vals <- sapply(idxs, function(idx) {
return(is_good_index(k, idx, coll))
})
return(idxs[vals])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment