[R-SIG-Finance] Zoo NA handling documentation?

Gabor Grothendieck ggrothendieck at gmail.com
Sun Jul 22 15:22:02 CEST 2007


There are some example here:

https://stat.ethz.ch/pipermail/r-sig-finance/2006q2/


On 7/22/07, icosa atropa <icos.atropa at gmail.com> wrote:
> Thank you so much for your previous help with zoo and lattice.  Following
> your guidance, I've found the zoo package very powerful.  The rollapply
> demos were also illuminating!
>
> I'm wondering if I've found some inconsistency with zoo documentation r.e.
> NA handling.
> Both na.omit and na.contiguous are mentioned as methods in the current CRAN
> pdf reference documentation.  The hyperlink for na.omit on p18 lead to p1,
> and there are no function defs for either in the docs.  Similarly, both
> ?na.omit and ?na.contiguous lead to function defs.  Are these unimplemented
> as generic functions?  I'm a bit confused as to the proper context in which
> to use na.omit and na.contiguous.
>
> best,
> christian
>
> On 7/8/07, Gabor Grothendieck <ggrothendieck at gmail.com > wrote:
> > Try this (and see ?xyplot.zoo for more info):
> >
> > # first run code in your post that creates the experiment object
> >
> > # create a time series from experiment
> > z <- zoo(matrix(experiment$meas, 25, byrow = TRUE))
> > colnames(z) <- c("NC", "NT", "SC", "ST")
> >
> > # add grid to existing plot
> > addGrid <- function() for(i in 1:2) {
> >   trellis.focus("panel", i, 1); panel.grid(); trellis.unfocus()
> > }
> >
> > zz <- z
> > colnames(zz) <- c("N", "NT", "S", "ST")
> > xyplot(zz, screens = c(1, 1, 2, 2), col = 1:2, layout = 2:1, type = "b")
> > addGrid()
> >
> > zz <- z
> > colnames(zz) <- c("C", "T", "SC", "ST")
> > xyplot(zz, screens = 1:2, col = c(1, 1, 2, 2), layout = 2:1, type = "b")
> > addGrid()
> >
> >
> > On 7/8/07, icosa atropa <icos.atropa at gmail.com> wrote:
> > > > Please provide something reproducible and
> > > > show what you want to do without zoo.
> > >
> > > The following example is contrived, but closely resembles my data.
> > >
> > > I pull my data from a database using RODBC - it comes in as a data.frame
> > > with factors, timestamp, and data all globbed together.  This is very
> > > convenient for plotting with lattice, but complicates time series
> analysis.
> > > I can't turn the object into a zoo directly due to the mixed
> factor/data.
> > > I've looked at fCalendar, whose timeSeries object has an recordtID
> slot...
> > >
> > >
> > > # Everything from here down tested with R 2.5.0
> > >
> > > experiment.layout = expand.grid( tx=c('control', 'treatment'), rep=c(
> 'N',
> > > 'S'), time=1:25)
> > > # ^^ block design experiment
> > >
> > > experiment = data.frame( experiment.layout, meas=rnorm(100) )
> > > # ^^the time-indexed dataframe of observations by
> > >
> > > experiment$meas=experiment$meas + c(1,-1,2,-2)
> > > # ^^experimental effects differ by bloco and treatment
> > >
> > > summary(experiment)
> > >
> > > require(lattice)
> > > #
> > > #First split condition on rep, grouping by tx
> > > #
> > > xyplot(meas ~ time | rep, data=experiment, groups=tx,
> > >                 panel=function(x, y, subscripts, groups) {
> > >                         panel.grid()
> > >                         panel.superpose(x, y, subscripts, groups)
> > >                  }
> > > )
> > >
> > > #
> > > #Next condition on tx, grouping by experiment
> > > #
> > > xyplot(meas ~ time | tx, data=experiment, groups=rep,
> > >                 panel=function(x, y, subscripts, groups) {
> > >                         panel.grid()
> > >                         panel.superpose(x, y, subscripts, groups)
> > >                  }
> > > )
> > >
> > > thanks again for your time!
> > > christian
> > >
> >
>
>
>
> --
> Far better an approximate answer to the right question, which is often
> vague, than the exact answer to the wrong question, which can always be made
> precise -- j.w. tukey



More information about the R-SIG-Finance mailing list