[R-SIG-Finance] print an xts object in reverse order
Jeffrey Ryan
jeffrey.ryan at lemnica.com
Wed Nov 16 03:31:46 CET 2011
For the record, if you really want to print it backwards, you can do this:
> as.matrix(x)[NROW(x):1,,drop=FALSE]
[,1]
2011-11-25 10
2011-11-24 9
2011-11-23 8
2011-11-22 7
2011-11-21 6
2011-11-20 5
2011-11-19 4
2011-11-18 3
2011-11-17 2
2011-11-16 1
HTH
Jeff
P.S. rev on an xts object is actually rev.zoo, so the same behavior
you get from zoo you get in xts.
On Tue, Nov 15, 2011 at 6:07 PM, Jeffrey Ryan <jeffrey.ryan at lemnica.com> wrote:
> You can't.
>
> xts enforces time order - if it didn't it would be nearly useless.
>
> If you really need to reverse the order, you should think twice about
> it. If upon further consideration you still need it reversed, you can
> coerce to something else to accommodate.
>
> rev(coredata(x))
> rev(as.matrix(x)
>
> or
>
> rev(as.zoo(x))
>
> The latter is strange to me, as it reverses the underlying series, but
> not the dates. Sort of alluding to the 'do you really want to do
> this...'
>
> Jeff
>
> On Tue, Nov 15, 2011 at 5:14 PM, Chris de Bleu <blue2bleu at yahoo.fr> wrote:
>> Hi,
>>
>> I would like to know how can I print an xts object in reverse order?
>>
>>
>> rev(xtsObject) always gives the same order as xtsObject.
>>
>> Thanks
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org 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.
>>
>
>
>
> --
> Jeffrey Ryan
> jeffrey.ryan at lemnica.com
>
> www.lemnica.com
> www.esotericR.com
>
--
Jeffrey Ryan
jeffrey.ryan at lemnica.com
www.lemnica.com
www.esotericR.com
More information about the R-SIG-Finance
mailing list