[R] zoo and coredata() classes

Gabor Grothendieck ggrothendieck at gmail.com
Tue Mar 3 17:00:53 CET 2009


On Tue, Mar 3, 2009 at 10:37 AM,  <rory.winston at gmail.com> wrote:
> Hi guys
>
> I have a reasonably basic question with zoo usage, but I havent been able
> to find a satisfactory workaround yet.
>
> Heres a simple example of what I'm talking about (the following data frame
> contains numeric columns that contains NAs):
>
>> head(ebs)
> time src tstamp code bid ask
> 1 2009-03-03 13:03:29.536 perf.Tib_listener 14980321164
> EBS.REC.EURJPY=EBS.NaE 123.48 NA
> 2 2009-03-03 13:03:29.786 perf.FilteringPublisher 14980565658 EUR.JPY.SPOT
> 123.48 123.51
> 3 2009-03-03 13:03:29.786 perf.Tib_listener 14980566116
> EBS.REC.EURJPY=EBS.NaE NA 123.51
> 4 2009-03-03 13:03:30.036 perf.FilteringPublisher 14980824852 EUR.JPY.SPOT
> 123.49 123.50
> 5 2009-03-03 13:03:30.051 perf.Tib_listener 14980835694
> EBS.REC.EURJPY=EBS.NaE 123.49 123.50
> 6 2009-03-03 13:03:30.520 perf.FilteringPublisher 14981302082 EUR.JPY.SPOT
> 123.49 123.51
>
>> class(ebs)
> [1] "data.frame"
>
>> class(ebs$bid)
> [1] "numeric"
>
>> any(is.na(ebs$bid))
> [1] TRUE
>
>> class(ebs$ask)
> [1] "numeric"
>
>> foo <- zoo(ebs)

The first argument to zoo cannot be a data frame.  From ?zoo

Usage:

     zoo(x = NULL, order.by = index(x), frequency = NULL)

Arguments:

       x: a numeric vector, matrix or a factor.

Also see Question #4 in the zoo faq. From within R:

library(zoo)
vignette("zoo-faq")




More information about the R-help mailing list