Created
August 7, 2013 23:02
-
-
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
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
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