[R] Ordeing Zoo object

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Wed Dec 9 07:55:35 CET 2009


On Tue, 8 Dec 2009, Bogaso wrote:

>
> Hi all, I would like to ask how to order a Zoo object? Consider following
> code
>
>> dat <- zooreg(rnorm(5), as.yearmon(as.Date("2001-01-01")), frequency=12)
>> dat
>  Jan 2001   Feb 2001   Mar 2001   Apr 2001   May 2001
> -0.8916124 -0.4516505  1.1305884 -1.4881309  0.3703734
>
> Here I want to order from last to 1st i.e. from May to Jan. So I used
> following code :
>
>> dat[5:1]
>  Jan 2001   Feb 2001   Mar 2001   Apr 2001   May 2001
> -0.8916124 -0.4516505  1.1305884 -1.4881309  0.3703734
>
> Therefore I am not getting what I desired. If someone points out the correct
> code I would be grateful.

The zoo object itself is always ordered by time. So it takes the 
observations you specified (5:1) and orders them by time again (so you get 
1:5). You need to extract the data without the time index and then proceed 
as usual:

   sort(coredata(dat))
or
   coredata(dat)[5:1]
etc.
Z

> Thanks,
> -- 
> View this message in context: http://n4.nabble.com/Ordeing-Zoo-object-tp955868p955868.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>




More information about the R-help mailing list