[R-SIG-Finance] yearweek creator in zoo

Gabor Grothendieck ggrothendieck at gmail.com
Thu Nov 8 14:58:04 CET 2007


Try this:

library(zoo)
methods(class = "yearmon")  # shows which methods are defined
zoo:::Ops.yearmon  # shows source to Ops method

etc.

or even better see zoo home page:
 http://R-Forge.R-project.org/projects/zoo/
or CRAN:
  http://cran.r-project.org/src/contrib/Descriptions/zoo.html

and just download the source and examine yearmon.R or
yearqtr.R.

Note that in certain cases you don't really have to do anything
depending on what methods you need.  For example, if you
decide that "yyyyww" is ok then this works out-of-the-box:

z1 <- zoo(1:3, c("200701", "200702", "200703"))
z2 <- zoo(11:12, c("200703", "200704"))
merge(z1, z2)

since character strings of that form are already totally ordered,
character strings already have the minimal needed methods
defined and zoo does not need to know what the actual meanings
you have attached to the strings are.   Numbers of the form
200701, 200702, etc. would also work out of the box for the same
reason.

On Nov 8, 2007 8:29 AM, Markus Loecher <markus at insightfromdata.com> wrote:
> Dear fellow zoo-package users,
> I am quite intrigued by the ability to define my own custom index
> class in zoo. The example given in the zoo vignette is the (already
> built-in) yearmon class defined as:
>
>        yearmon <- function(x) structure(floor(12*x + .0001)/12, class =
> "yearmon")
>
> As my understanding of and practice with custom structures in R is
> rather weak, I am not entirely sure how to define my own weekly index,
> in particular, how would I add methods for human readable character
> representations and Ops and MATCH methods ?
> Any example would be greatly appreciated !
>
> Thanks in advance,
>
> Markus
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list