Created
December 7, 2012 19:24
-
-
Save allenaven/4235768 to your computer and use it in GitHub Desktop.
Match a time datum with the nearest time in a vector of times
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
### Function to match a time datum with the closest time in another (for, say, finding water heights) | |
closest.time <- function(in.datum, ref.vec){ | |
return(which.min(abs(difftime(in.datum, ref.vec, units="secs")))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There must be a better way to do this. I need to take an "algorithms" class.