[R] zoo object

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Mon Jan 14 16:47:56 CET 2008


On Mon, 14 Jan 2008, Gabor Grothendieck wrote:

> Create a sequence of dates, dd, spanning the data and
> then merge the data with a zero width zoo object
> having those dates.  Finally na.locf will fill in the
> NAs just generated with the last ocurrence carried forward.
>
> z <- zoo(c(0.007306621, 0.007659046, 0.007681013,
> 	0.007817548, 0.007847579, 0.007867313),
> 	as.Date(c("1993-01-01", "1993-01-09", "1993-01-16",
> 	"1993-01-23", "1993-01-30", "1993-02-06")))
>
> dd <- seq(min(time(z)), max(time(z)), "day")
> na.locf(merge(z, zoo(, dd)))

I was just writing a reply with virtually identical code. The only
difference ist that
  start(z), end(z)
might be a bit more evocative thatn
  min(time(z)), max(time(z))
but leads, of course, to identical results.
Z

>
> On Jan 14, 2008 9:02 AM, Vishal Belsare <shoot.spam at gmail.com> wrote:
> > I have an ordered series of 3 month t-bill rates (annual). I transform
> > this to a daily series, however, the observations are constructed only
> > from the dates on which the t-bills were issued, which is every week.
> >
> > So now I have ordered observations of the daily 'risk-free rate' for
> > one day every week. I want to expand this zoo object to give a value
> > for every day, and to do so, copy the previous value to the next date
> > (which is as yet not in the zoo object).
> >
> > For example:
> >
> > head(rf)
> >  1993-01-01  1993-01-09  1993-01-16  1993-01-23  1993-01-30  1993-02-06
> > 0.007306621 0.007659046 0.007681013 0.007817548 0.007847579 0.007867313
> >
> > I want to insert values between each of the dates, and copy the
> > previous value for those days. Any suggestions would be greatly
> > appreciated. Thanks in anticipation.
> >
> >
> > Regards,
> >
> > Vishal Belsare
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>




More information about the R-help mailing list