Created
July 28, 2014 16:59
-
-
Save InzamamRahaman/9b13a9c99bf521c59dbd to your computer and use it in GitHub Desktop.
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
# 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