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) > datJan 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. 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.
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. > >
And how about if I want to order the series from the smallest to the largest value, keeping the date index in order to see when the values were predominantly negative etc... Thanks, Marco -- View this message in context: http://r.789695.n4.nabble.com/Ordeing-Zoo-object-tp955868p3054192.html Sent from the R help mailing list archive at Nabble.com.
On Mon, Nov 22, 2010 at 1:35 PM, Manta <mantino84 at libero.it> wrote:> > And how about if I want to order the series from the smallest to the largest > value, keeping the date index in order to see when the values were > predominantly negative etc... >If you just want to look at it in this order then: as.data.frame(dat)[length(dat):1,,drop = FALSE] -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com