Skip to content

Instantly share code, notes, and snippets.

@walkerjeffd
Created August 7, 2013 23: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 walkerjeffd/6179788 to your computer and use it in GitHub Desktop.
Save walkerjeffd/6179788 to your computer and use it in GitHub Desktop.
R function to test is vector of datetimes is regular and continuous
is.regular <- function(x) {
# returns TRUE if vector x of POSIXct datetimes is continuous and regular
# by checking if there are more than one unique difftime between each row
x.difftime <- difftime(x[2:length(x)], x[1:(length(x)-1)], units='secs')
if (length(levels(factor(x.difftime))) > 1) {
return (FALSE)
} else {
return (TRUE)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment