Skip to content

Instantly share code, notes, and snippets.

@walkerjeffd
Created August 7, 2013 23:02
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/6179773 to your computer and use it in GitHub Desktop.
Save walkerjeffd/6179773 to your computer and use it in GitHub Desktop.
R function for creating a regular and continuous zoo object from two vectors of dates/datetimes and values with optional fill values
zoo.regular <- function(dates, values, by="hour", fill=NA) {
# convert time series to regular zoo object
require(zoo)
z <- zoo(values, dates)
z <- merge(z, zoo(, seq(floor_date(start(z), 'day'),
ceiling_date(end(z), 'day'),
by)),
fill=fill)
z <- z[1:(length(z)-1)]
return(z)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment