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

Ajay Shah ajayshah at mayin.org
Tue May 25 16:05:07 CEST 2010


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.



More information about the R-SIG-Finance mailing list