[R-SIG-Finance] can I 'attach' a zoo object?

Gabor Grothendieck ggrothendieck at gmail.com
Tue May 25 17:05:15 CEST 2010


The majority of the time is taken by as.list.zoo, not by attach
itself.  At any rate, normally the fact that it takes an entire second
to do this for a large object is not important since we only attach it
once in the session anyways.  The time to access the data itself is
not impacted and that is normally the important part.

On Tue, May 25, 2010 at 10:05 AM, Ajay Shah <ajayshah at mayin.org> wrote:
> On Tue, May 25, 2010 at 03:28:42PM +0200, Matthieu Stigler wrote:
>> Thanks to all of you for your prompt answer!
>>
>> attach(as.list(zoo1))
>>
>> is the solution that best fit my needs!
>
> You do realise that it's quite costly, so for large objects you have
> to think carefully about this. Unlike with data frames where attach()
> is free.
>
> If I try:
>
>  library(zoo)
>  z <- zoo(matrix(runif(1000000), ncol=100), order.by=1:10000)
>  d <- as.data.frame(z)
>  system.time(attach(d))
>  system.time(attach(as.list(z)))
>
> I get:
>
>> system.time(attach(d))
>   user  system elapsed
>  0.016   0.007   0.025
>> system.time(attach(as.list(z)))
>   user  system elapsed
>  0.572   0.280   0.979
>
> So it's syntactic sugar but basically you are doing costly casting
> when you might think you are merely attaching.
>
> --
> Ajay Shah                                      http://www.mayin.org/ajayshah
> ajayshah at mayin.org                             http://ajayshahblog.blogspot.com
> <*(:-? - wizard who doesn't know the answer.
>
> _______________________________________________
> 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.
> -- Also note that this is not the r-help list where general R questions should go.
>



More information about the R-SIG-Finance mailing list