Skip to content

Extracting specific rows from irregular zoo object and merging with a regular zoo object

4 messages · Sergey Goriatchev, Gabor Grothendieck

#
Hello, everyone

I have the following problem:
Say I have an irregular zoo timeseries like this:

a <- zoo(rep(1:9), as.Date(c("2009-03-20", "2009-03-27", "2009-04-24",
"2009-04-25", "2009-04-30", "2009-05-15", "2009-05-22", "2009-05-29",
"2009-06-26")))

and I have regular zoo timeseries like this:

b <- zoo(rep(1:4), as.Date(c("2009-03-31", "2009-04-30", "2009-05-31",
"2009-06-30")))
day of each month (creating series "c"). Then I have to merge these
values with "b", such that the result has the index of "c".

How could I do this most efficiently?

Thank you in advance!

Best,
Sergey

--
Simplicity is the last step of art./Bruce Lee
#
Omit rep.  You just want  a <- zoo(1:9, ...). To get the last day of
the month you don`t need b since as.Date.yearmon will give it with the
argument frac = 1:
2009-03-31 2009-04-30 2009-05-31 2009-06-30
         2          5          8          9
On Thu, Apr 8, 2010 at 11:18 AM, Sergey Goriatchev <sergeyg at gmail.com> wrote:
#
Thank you, Gabor! This is a very elegant solution.
But instead of general last day of month in the index, how can I have
last day of each month as they are presented in "a", for example, not
March 31, but March 27?

Regards,
Sergey

On Thu, Apr 8, 2010 at 17:27, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:

  
    
#
On Thu, Apr 8, 2010 at 11:42 AM, Sergey Goriatchev <sergeyg at gmail.com> wrote:
Try this:
2009-03-27 2009-04-30 2009-05-29 2009-06-26
        2          5          8          9

or this:
2009-03-27 2009-04-30 2009-05-29 2009-06-26
        2          5          8          9

Note that the examples in ?aggregate.zoo include some that are very
similar examples are shown here.

Also see ?ave .