Skip to content
Prev 6145 / 15274 Next

can I 'attach' a zoo object?

On Tue, May 25, 2010 at 03:28:42PM +0200, Matthieu Stigler wrote:
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:
user  system elapsed 
  0.016   0.007   0.025
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.