[R-SIG-Finance] can I 'attach' a zoo object?
Matthieu Stigler
matthieu.stigler at gmail.com
Tue May 25 15:28:42 CEST 2010
Thanks to all of you for your prompt answer!
attach(as.list(zoo1))
is the solution that best fit my needs!
Thanks!
Matthieu
Achim Zeileis a écrit :
> 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!
>>
>> _______________________________________________
>> 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