On Tue, 25 May 2010, Matthieu Stigler wrote:
Hi
When importing a big data frame, I like to "attach" its variables so
they are direclty available. I don't see how to do this with zoo...
Does anyone has an idea how I could do that?
It can't be done directly as attach() is non-generic and will tell you
R> attach(zoo1)
Error in attach(zoo1) :
'attach' only works for lists, data frames and environments
You can do two things: (1) Use with() which I personally typically
prefer over attach()/detach() anyway. (2) Create a data.frame where
every column is a zoo series and attach that.
R> with(zoo1, vara + varb)
2003-02-02 2003-02-04 2003-02-08
0.8189917 1.1104191 0.8113533
Or:
R> zoo2 <- merge(zoo1, retclass = "data.frame")
R> names(zoo2) <- colnames(zoo1)
R> attach(zoo2)
R> vara + varb
2003-02-02 2003-02-04 2003-02-08
0.8189917 1.1104191 0.8113533
hth,
Z
Take a zoo object:
library(zoo)
zooframe<-matrix(runif(3*26), nrow=3, dimnames=list(letters[1:3],
paste("var", letters, sep="")))
zoo1 <-zoo(zooframe, order.by=as.Date("2003-02-01") + c(1, 3, 7))
Can I 'attach' it, so its variables become accessible to user workspace?
attach(zoo1)
#does not work...
Thanks!