Skip to content

Instantly share code, notes, and snippets.

@allenaven
Created December 7, 2012 19:24
Show Gist options
  • Save allenaven/4235768 to your computer and use it in GitHub Desktop.
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
### 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"))))
}
@allenaven
Copy link
Author

There must be a better way to do this. I need to take an "algorithms" class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment