Skip to content
Prev 205461 / 398506 Next

zero-fill absent data

The zoo package's merge.zoo routines has a fill=0 argument so:  create
an expanded index, ix, and then in the next line create zoo objects
from the data and the expanded index and merge them together.  Finally
in the last line convert back to a data frame.

library(zoo)
ix <- with(frame, seq(min(V1), max(V1)))
z <- with(frame, merge(zoo(V2, V1), zoo(, ix), fill = 0))
data.frame(V1 = time(z), V2 = coredata(z))


On Tue, Jan 5, 2010 at 5:39 PM, Dan Kortschak
<dan.kortschak at adelaide.edu.au> wrote: